我必须将python脚本从使用Python 2.6的服务器移动到另一个使用2.4的服务器上.
我不得不做一些修改.现在我卡住了.我继续得到这个错误
File "subprocess.py", line 975, in _execute_child
raise child_exception
OSError: [Errno 8] Exec format error
Run Code Online (Sandbox Code Playgroud)
我的日志输出:
Traceback (most recent call last):
File "/cnfs/dev/regions/que/cli/rpntrans_requests/scripts/0.6a/process.py", line 281, in ?
process(filename)
File "/cnfs/dev/regions/que/cli/rpntrans_requests/scripts/0.6a/process.py", line 259, in process
outputs = transformations[tr.tag](file).execute()
File "/cnfs/dev/regions/que/cli/rpntrans_requests/scripts/0.6a/process.py", line 114, in execute
t.execute()
File "/cnfs/dev/regions/que/cli/rpntrans/current/rpntrans.py", line 113, in execute
last_step.execute()
File "/cnfs/dev/regions/que/cli/rpntrans/current/rpntrans.py", line 941, in execute
stdout=sys.stdout, stderr=sys.stderr
File "subprocess.py", line 413, in call
return Popen(*args, **kwargs).wait()
File "subprocess.py", line 543, in __init__
errread, errwrite)
File "subprocess.py", …Run Code Online (Sandbox Code Playgroud) 我的IPython Notebook项目中有一个原始文本单元格。
有没有一种方法可以通过内置函数或类似方法将文本作为字符串获取?
我正在寻找输出Python中两个数组的第一个差异的索引的最快方法.例如,让我们采用以下两个数组:
test1 = [1, 3, 5, 8]
test2 = [1]
test3 = [1, 3]
Run Code Online (Sandbox Code Playgroud)
比较test1和test2,我想输出1,而test1和test3的比较应该输出2.
换句话说,我寻找相当于声明:
import numpy as np
np.where(np.where(test1 == test2, test1, 0) == '0')[0][0]
Run Code Online (Sandbox Code Playgroud)
具有不同的阵列长度.
任何帮助表示赞赏.
我想安装 scipy 包,我知道这是一个重复的问题,但我已经尝试了所有这些,但没有找到合适的解决方案。
写这个时: import scipy
它执行成功。但是当我尝试这个时:
import scipy.spatial
Run Code Online (Sandbox Code Playgroud)
我收到这条消息:
Traceback (most recent call last):
File "C:/Users/Hamid/Documents/kodeyaro/kodefolani.py", line 41, in <module>
from scipy.spatial import Delaunay
File "C:\Python27\lib\site-packages\scipy\spatial\__init__.py", line 92, in module>
from .qhull import *
ImportError: DLL load failed: The specified module could not be found.
Run Code Online (Sandbox Code Playgroud)
我该怎么办?
我为Python 2和3安装了两个版本的Anaconda。
我添加了路径。
我使用Anaconda提示。
python program.py
Run Code Online (Sandbox Code Playgroud)
假设我使用的是Python3。例如,它无法理解:
print "hello!"
Run Code Online (Sandbox Code Playgroud)
我试过了:
py program.py
py -2 program.py
Run Code Online (Sandbox Code Playgroud)
但是他们没有用。如何运行Python 2程序?
如果输入:
python
Run Code Online (Sandbox Code Playgroud)
在Acaconda提示下,然后说:
python 3.5.1. Anaconda 2.4.1
Run Code Online (Sandbox Code Playgroud)
因此,提示是假设我正在使用Python 3。
但是我有用Python 2编写的程序和用Python 3编写的程序。
我想在两者之间顺利切换。我应该怎么做?
这段代码的结果:
!/usr/bin/python
from sys import argv
script, file = argv
apertura = open(file,'r')
for a in apertura:
print(apertura.read())
Run Code Online (Sandbox Code Playgroud)
是:
quarta quinta
sesta
settima
ottava
nona
Run Code Online (Sandbox Code Playgroud)
我想用read()打印整个文件.上面的代码跳过一些行.为什么?
文件内容如下:
prima seconda terza
quarta
quinta
sesta
settima
ottava
nona
Run Code Online (Sandbox Code Playgroud) 我有一个像这样的数据框:
该数据框有几列。两个是类型float:price和change,而volme和amount是类型int。我使用方法df.values.tolist()change df来列出并获取数据:
datatmp = df.values.tolist()
print(datatmp[0])
[20160108150023.0, 11.12, -0.01, 4268.0, 4746460.0, 2.0]
Run Code Online (Sandbox Code Playgroud)
所有类型int都df更改为float类型。我的问题是为什么int类型会改变为float类型?我怎样才能得到int我想要的数据?
我正在学习Python,我的任务是:
我有很多文件,都有不同的名字,每个长7个字符.我能够改变扩展,但感觉非常笨重.我很肯定有一种更清洁的方式来写下面的内容(但它的功能,所以没有对该注释的投诉):
import os, sys
path = 'C:/Users/dana/Desktop/text_files_2/'
for filename in os.listdir(path):
if filename.endswith('.rtf'):
newname = filename.replace('.rtf', '.txt')
os.rename(filename, newname)
elif filename.endswith('.py'):
newname = filename.replace('.py', '.txt')
os.rename(filename, newname)
elif filename.endswith('.TEXT'):
newname = filename.replace('.TEXT', '.txt')
os.rename(filename, newname)
elif filename.endswith('.text'):
newname = filename.replace('.text', '.txt')
os.rename(filename, newname)
Run Code Online (Sandbox Code Playgroud)
我还有一点问题:
我无法弄清楚如何将"file_"添加到每个文件名的开头[ 你会认为这将是一个简单的部分 ].我试过将newname声明为
newname = 'file_' + str(filename)
Run Code Online (Sandbox Code Playgroud)
它然后声明文件名未定义.
对我现有的两个问题的任何帮助都将不胜感激.
我的问题是:如何从现有的 id 列有效地签署数据唯一的 id 号?例如:我有两列 [household_id] 和 [person_no]。我尝试创建一个新列,查询将是:home_id + '_' + person_no。
这是一个示例:
hh_id pno
682138 1
365348 1
365348 2
Run Code Online (Sandbox Code Playgroud)
想拿到:
unique_id
682138_1
365348_1
365348_2
Run Code Online (Sandbox Code Playgroud)
并将此 unique_id 添加为新列。我正在应用 Python。我的数据非常大。任何有效的方法都会很棒。谢谢!
我想使用Python 3 is_emoji检查字符串是否只包含一个表情符号.例如,有一个函数检查字符串是否只有一个表情符号.
def is_emoji(s):
pass
is_emoji("") #True
is_emoji("??") #False
Run Code Online (Sandbox Code Playgroud)
我尝试使用正则表达式但emojis没有固定长度.例如:
print(len("??".encode("utf-8"))) # 6
print(len("".encode("utf-8"))) # 4
Run Code Online (Sandbox Code Playgroud)