转 php python 知识点

 ##感谢zyp

acconda 软件的 spyder 软件,可以方便用于python 调试, windows 检查格式

感谢

 

往右移动4格

先鼠标选中要移动的多行代码,然后按tab建,按一次移动4格

往左边移动

同样选中多行,然后按shift+tab移动

或者选择UE 编辑

#感谢 www.runoob.com

关键字参数

关键字参数和函数调用关系紧密,函数调用使用关键字参数来确定传入的参数值。

使用关键字参数允许函数调用时参数的顺序与声明时不一致,因为 Python 解释器能够用参数名匹配参数值。

以下实例在函数 printme() 调用时使用参数名:

实例(Python 2.0+)

#!/usr/bin/python # -*- coding: UTF-8 -*- #可写函数说明 def printme( str ): "打印任何传入的字符串" print str return #调用printme函数 printme( str = "My string")
 
#!/usr/bin/python
# -*- coding: UTF-8 -*-
 
#可写函数说明
def printme( str ):
   "打印任何传入的字符串"
   print str
   return
 
#调用printme函数
printme( str = "My string")

  

##### 感谢pythonf

Error taberror:缩进中制表符和空格的使用不一致,Python,报错,TabErrorinconsistentuseoftabsandspacesinindentation

发表时间:2020-07-04

一、出现原因

在修改python文件的时候,运行程序出现报错: TabError: inconsistent use of tabs and spaces in indentation

出现这个错误是因为笔者在notepad++ 遇到的都是 看似有空格但实际没有空格 引起的。
打开notepad++ 显示空格选项就知道这个位置是不是真的有空格了。

二、notepad++ 显示 空格

在notrpad++中打开显示空格选项:
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
从上图可以发现,val_m 前面并不是空格。
主要原因是制表符Tab 并不是 四个空格 而出现的问题。

三、解决方法

解决方法:设置–>首选项,然后找到语言,勾选右下角的 替换为表格 ,这样就可以保证 一个 Tab键 = 4个空格。
在这里插入图片描述
在这里插入图片描述

然后就可以同时使用 Tab键 和空格了。

参考链接:
[1] Python中常出现TabError: inconsistent use of tabs and spaces in indentation错误解决方法 https://blog.csdn.net/qq_41096996/article/details/85947560
[2] 把Notepad++的tab设置为四个空格 https://www.cnblogs.com/jyfootprint/p/9409934.html

文章来源互联网,如有侵权,请联系管理员删除。邮箱:417803890@qq.com / QQ:417803890

###感谢廖雪峰

https://www.jb51.net/article/65072.htm

调试Python程序代码的几种方法总结

logging

把print替换为logging是第3种方式,和assert比,logging不会抛出错误,而且可以输出到文件:

1
2
3
4
5
6
7
# err.py
import logging
 
s = '0'
n = int(s)
logging.info('n = %d' % n)
print 10 / n

logging.info()就可以输出一段文本。运行,发现除了ZeroDivisionError,没有任何信息。怎么回事?

别急,在import logging之后添加一行配置再试试:

1
2
import logging
logging.basicConfig(level=logging.INFO)

看到输出了:

1
2
3
4
5
6
$ python err.py
INFO:root:n = 0
Traceback (most recent call last):
 File "err.py", line 8, in <module>
  print 10 / n
ZeroDivisionError: integer division or modulo by zero

这就是logging的好处,它允许你指定记录信息的级别,有debug,info,warning,error等几个级别,当我们指定level=INFO时,logging.debug就不起作用了。同理,指定level=WARNING后,debug和info就不起作用了。这样一来,你可以放心地输出不同级别的信息,也不用删除,最后统一控制输出哪个级别的信息。

logging的另一个好处是通过简单的配置,一条语句可以同时输出到不同的地方,比如console和文件。

###感谢codeigniter 志愿者   upload 方法

https://codeigniter.org.cn/userguide3/libraries/file_uploading.html?highlight=%E4%B8%8A%E4%BC%A0

修改为: 

$config['max_width'] = 0;
$config['max_height'] = 0;

修改跟目录位置

        $config['upload_path'] = './uploads/';//根目录下的uploads文件(即相对于入口文件)

C:wamp64wwwmyapp

php数组的定义、调用和修改
array() 创建数组,带有键和值。如果在规定数组时省略了键,则生成一个整数键,这个 key 从 0 开始,然后以 1 进行递增 [6]  。
要用 array() 创建一个关联数组,可使用 => 来分隔键和值。
语法
  array(key => value)
  参数key可选。规定 key,类型是数值或字符串。如果未设置,则生成整数类型的 key。
  value必需。规定值。
  <h3><font color="#CC6600">输出aaaaaabbbbbb</font></h3>
  <?php
  $array = array("key1" => "aaaaaa", 2 => "bbbbbb"); //数组的创建
  echo $array["key1"]; //输出aaaaaa
  echo $array[2]; //输出bbbbbb
  ?>

遍历数组

 

###感谢By: CodexWorld    download 方法

//https://www.codexworld.com/codeigniter-download-file-from-database/

// insert into files values ('1','tt','tt',now(),now(),1)

https://www.web-development-blog.com/php-download-file-script/

https://stackoverflow.com/questions/11903436/write-a-text-file-and-force-to-download-with-php

 感谢

aed Aug 10 '12 at 14:15
 

$myfile = fopen("d:/newfile.txt", "w") or die("Unable to open file!");
$txt = "Bill Gates ";
fwrite($myfile, $txt);
fwrite($myfile,$end_timestamp);
$txt = "Bill Gates ";
fwrite($myfile, $txt);
$txt = "Steve Jobs ";
fwrite($myfile, $txt);
fclose($myfile);


header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename('d:/newfile.txt'));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize('d:/newfile.txt'));
readfile('d:/newfile.txt');
exit;

原文地址:https://www.cnblogs.com/feiyun8616/p/13255761.html