草庐IT

byte-compiling

全部标签

python - 我可以在没有安装 Python 的情况下以某种方式 "compile"在 PC 上运行 python 脚本吗?

所以我有一个Python脚本:myscript.py我是这样执行的:pythonD:\myscript.py但是,我必须安装Python并将其包含在PATH环境变量中才能正常工作。是否有可能以某种方式将Python可执行文件与Python脚本“捆绑”在一起,这样其他人就可以在没有Python的情况下在他们的PC上运行它?如果它只能在Windows中工作就可以了。编辑:在尝试compile.py后,我得到了这个错误:Traceback(mostrecentcalllast):File"D:\stuff\compile.py",line4,inimportpy2exeImportError

python - 将 .csv 文件从 URL 读取到 Python 3.x - _csv.Error : iterator should return strings, not bytes(您是否以文本模式打开文件?)

我已经为这个简单的问题苦苦挣扎了太久,所以我想我会寻求帮助。我正在尝试将国家医学图书馆ftp站点的期刊文章列表读入Python3.3.2(在Windows7上)。期刊文章位于.csv文件中。我已经尝试了以下代码:importcsvimporturllib.requesturl="ftp://ftp.ncbi.nlm.nih.gov/pub/pmc/file_list.csv"ftpstream=urllib.request.urlopen(url)csvfile=csv.reader(ftpstream)data=[rowforrowincsvfile]这会导致以下错误:Traceba

python - UnicodeDecodeError : 'ascii' codec can't decode byte 0xe0 in position 0: ordinal not in range(128)

在我的一台机器上,当我使用google应用程序引擎或django时出现错误。例如:app.yamlapplication:demas1252cversion:1runtime:pythonapi_version:1handlers:-url:/imagesstatic_dir:images-url:/cssstatic_dir:css-url:/jsstatic_dir:js-url:/.*script:demas1252c.pydemas1252c.pyimportcgiimportwsgiref.handlersfromgoogle.appengine.ext.webappimpo

Python3 错误 : TypeError: Can't convert 'bytes' object to str implicitly

我正在learnpythonthehardway中的练习41并不断收到错误:Traceback(mostrecentcalllast):File".\url.py",line72,inquestion,answer=convert(snippet,phrase)File".\url.py",line50,inconvertresult=result.replace("###",word,1)TypeError:Can'tconvert'bytes'objecttostrimplicitly我使用的是python3,而书籍使用的是python2,所以我做了一些更改。这是脚本:#!/usr

python - 在不知道 'compile' 时间的属性名称的情况下,在 Python 中复制 Google App Engine 数据存储中的实体

在我正在编写的PythonGoogleAppEngine应用程序中,我有一个存储在数据存储区中的实体,我需要检索该实体,制作它的精确副本(key除外),然后将该实体放回去在。我应该怎么做?特别是,在执行此操作时是否需要注意任何警告或技巧,以便获得我期望的副本而不是其他内容。ETA:好吧,我试过了,但确实遇到了问题。我想以这样一种方式制作我的副本,这样我在编写代码时就不必知道属性的名称。我的想法是这样做:#theThing=aparticularentitywepullfromthedatastorewithmodelThingcopyThing=Thing(user=user)fort

python - UnicodeDecodeError : 'ascii' codec can't decode byte 0xc3 in position 23: ordinal not in range(128)

当我尝试连接它时,当字段包含“ñ”或“´”时,我会收到UnicodeDecodeError。如果包含“ñ”或“´”的字段是最后一个,我不会出错。#...nombre=fabricanombre=nombre.encode("utf-8")+'-'+sector.encode("utf-8")nombre=nombre.encode("utf-8")+'-'+unidad.encode("utf-8")#...returnnombre有什么想法吗?非常感谢! 最佳答案 您正在编码为UTF-8,然后重新-编码为UTF-8。Python只

python - 类型错误 : a bytes-like object is required, 不是 'str'

以下是尝试使用套接字修改用户提供的输入的代码:fromsocketimport*serverName='127.0.0.1'serverPort=12000clientSocket=socket(AF_INET,SOCK_DGRAM)message=input('Inputlowercasesentence:')clientSocket.sendto(message,(serverName,serverPort))modifiedMessage,serverAddress=clientSocket.recvfrom(2048)print(modifiedMessage)clientSo

python : Get size of string in bytes

我有一个要通过网络发送的字符串。我需要检查它所代表的总字节数。sys.getsizeof(string_name)返回额外的字节。例如sys.getsizeof("a")返回22,而一个字符在python中仅表示为1个字节。有没有其他方法可以找到这个? 最佳答案 如果你想要字符串中的字节数,这个函数应该可以很好地为你做。defutf8len(s):returnlen(s.encode('utf-8'))你得到奇怪数字的原因是因为字符串是python中的实际对象,所以封装在字符串中的是一堆其他信息。这很有趣,因为如果您查看我将字符串编

Python 3 TypeError : must be str, not bytes with sys.stdout.write()

我正在寻找一种从python脚本运行外部进程并在执行期间打印其标准输出消息的方法。下面的代码有效,但在运行时不打印标准输出。当它退出时,我收到以下错误:sys.stdout.write(nextline)TypeError:mustbestr,notbytesp=subprocess.Popen(["demo.exe"],stdout=subprocess.PIPE,stderr=subprocess.PIPE)#PollprocessfornewoutputuntilfinishedwhileTrue:nextline=p.stdout.readline()ifnextline=='

python - PIP 安装 Numpy 抛出错误 "ascii codec can' t decode byte 0xe2"

我在新构建的计算机上安装了新安装的Ubuntu。我刚刚使用apt-get安装了python-pip。现在,当我尝试pipinstallNumpy和Pandas时,它会出现以下错误。我在SO和Google上的很多地方都看到过这个错误,但我一直无法找到解决方案。有人提到这是一个错误,一些线程只是死了......这是怎么回事?Traceback(mostrecentcalllast):File"/usr/bin/pip",line9,inload_entry_point('pip==1.5.4','console_scripts','pip')()File"/usr/lib/python2.