如何检查对象是否是文件?
>>> f = open("locus.txt", "r")
>>> type(f)
<class '_io.TextIOWrapper'>
>>> isinstance(f, TextIOWrapper)
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
isinstance(f, TextIOWrapper)
NameError: name 'TextIOWrapper' is not defined
>>> isinstance(f, _io.TextIOWrapper)
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
isinstance(f, _io.TextIOWrapper)
NameError: name '_io' is not defined
>>> isinstance(f, _io)
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
isinstance(f, _io)
NameError: name '_io' is not defined
>>>
Run Code Online (Sandbox Code Playgroud)
我有f一个文本文件的变量.当我打印 …
我的代码:
logging.warning('FASE VALIDACIÓN TITULOS DE COLUMNAS DE DATOS NO SUPERADA. compruebe los nombres de los títulos de las columnas en datos.csv)')
Run Code Online (Sandbox Code Playgroud)
.log文件中的输出:
WARNING:root:FASE VALIDACI?N TITULOS DE COLUMNAS DE DATOS NO SUPERADA. compruebe los nombres de los t?tulos de las columnas en datos.csv)
Run Code Online (Sandbox Code Playgroud)
然后我尝试了这个:
logging.basicConfig(filename=nombreFicheroLog, encoding="utf-8", level=logging.DEBUG)
Run Code Online (Sandbox Code Playgroud)
但它不起作用.然后我尝试了这个:
logging.warning(u'FASE VALIDACIÓN TITULOS DE COLUMNAS DE DATOS NO SUPERADA. compruebe los nombres de los títulos de las columnas en datos.csv)')
Run Code Online (Sandbox Code Playgroud)
但输出是一样的.
我如何编码.log文件以支持UTF-8?
PS我正在使用Python3.
(我试过看,但所有其他答案似乎都在使用urllib2)
我刚刚开始尝试使用请求,但我仍然不太清楚如何从页面发送或请求其他内容.例如,我会的
import requests
r = requests.get('http://google.com')
Run Code Online (Sandbox Code Playgroud)
但我不知道现在怎么做,例如,使用提供的搜索栏进行谷歌搜索.我已经阅读了快速入门指南,但我对HTML POST等不是很熟悉,所以它并没有太大帮助.
有什么干净而优雅的方式来做我要问的事吗?
每当我尝试使用Pycharm在GitHub中推送存储库时,它就会失败.
Push failed: fatal: Authentication failed for 'https://github.com/(my github repository)/'
Run Code Online (Sandbox Code Playgroud)
在Settings-> Version Control-> GitHub中,我填写了Host,Loging和Password(Auth Type:Password)字段.测试它:"连接成功"
在Settings-> Version Control-> Git中,路径到Git可执行文件使用完整路径,SSH可执行文件:Buil-in
Pycharm版本3.1.1 Git版本1.8.4.msysgit.0在Win 7上.
为什么这个代码
>>> i=1
>>> add_one=lambda x:x+i
>>> my_list=[add_one(i) for i in [0,1,2]]
Run Code Online (Sandbox Code Playgroud)
在Python 2.7中抛出此结果:
>>> my_list
[0, 2, 4]
Run Code Online (Sandbox Code Playgroud)
但是Python 3.3中的相同代码会抛出另一个结果:
>>> my_list
[1, 2, 3]
Run Code Online (Sandbox Code Playgroud)
对我来说,Python 2.7的结果更有意义,因为'i'变量与调用lambda函数的名称范围相同.我不理解Python的两个分支中lambdas函数的这些不等行为.
我有一张包含混合格式数据(日期、双精度、字符串等)的工作表。我在lookup_range中搜索值(my_index),并且我想检索数据以更改其他工作表中的单元格。它工作正常,但是当 VLookup 返回的值是日期并且我将其设置到另一张表时,它会丢失其日期格式。
Dim lookup_range As Range
Dim my_index, my_value As Variant
my_value = Application.VLookup(my_index, lookup_range, num_col, False)
Sheets(3).Cells(num_row, last_col_s1 + num_col - 1).Value = my_value
Run Code Online (Sandbox Code Playgroud)
因此,当lookup_range中的数据是02/05/2014sheet-3中显示的数据时,看起来像41761。
我需要保留lookup_range中数据的原始数据格式。
如何获得符号链接的绝对路径?如果我按以下方式执行此操作:
char buf[100];
realpath(symlink, buf);
Run Code Online (Sandbox Code Playgroud)
我不会得到符号链接的绝对路径,但我会得到这个符号链接链接到的绝对路径.现在我的问题是:如果我想获得符号链接本身的abs路径怎么办?Linux c中有没有允许我这样做的功能?注意:我想要实现的是符号链接本身的绝对路径.不是它指向的路径!例如,smybolic链接的相对路径是:Task2/sym_lnk,我想要它的abs路径,可以是:home/user/kp/Task2/sym_lnk
随着str.format()我可以使用元组accesing参数:
>>> '{0}, {1}, {2}'.format('a', 'b', 'c')
'a, b, c'
Run Code Online (Sandbox Code Playgroud)
或者
>>> t = ('a', 'b', 'c')
>>> '{0}, {1}, {2}'.format(*t)
'a, b, c'
Run Code Online (Sandbox Code Playgroud)
但是对于以“f”(f 字符串)为前缀的新格式化字符串文字,我该如何使用元组?
f'{0}, {1}, {2}'.(*t) # doesn't work
Run Code Online (Sandbox Code Playgroud) 现在我正在使用iMacros从Web中提取数据并填写提交数据的表单.
但是iMacros是一种昂贵的工具.我需要一个免费的图书馆,我已经阅读了Scrapy的数据挖掘.使用它进行编程我是一个更复杂的问题,但金钱规则.
问题是我是否可以用Scrapy填写html表单并提交到网页.我不想使用Javascript,我想只使用Python脚本.
我在http://doc.scrapy.org/中搜索过,但我没有发现任何关于form-submit的信息.
我想检索 Sqlite3 数据库的前 100 行:
\n\nconnection = sqlite3.connect(\'aktua.db\')\ncursor = connection.cursor()\n\nprint(\'Actual \\tCliente \\tHist\xc3\xb3rica\')\ncursor.execute("SELECT * FROM Referencias WHERE r_aktua LIKE \'%K\'").fetchmany(size=100)\n\nfor row in cursor:\n print(\'%s \\t%s \\t%s\' % row)\n\ncursor.close()\nconnection.close()\nRun Code Online (Sandbox Code Playgroud)\n\n我的代码检索数据库的所有行(+4000)。
\n我已阅读sqlite3.Cursor.fetchmany 文档和SQLite Python 教程。
怎么了?
\npython ×7
python-3.x ×4
c ×1
class ×1
encoding ×1
excel ×1
fetch ×1
form-submit ×1
formatting ×1
git ×1
github ×1
lambda ×1
logging ×1
pycharm ×1
python-2.x ×1
python-3.6 ×1
scrapy ×1
sqlite ×1
tuples ×1
vba ×1
vlookup ×1
web-scraping ×1
windows ×1