我使用的是petl软件包,我使用python3.4在virtulaenv中使用pip安装了这个包。当我试图测试petl包是否正确地安装在python shell中时,我这样做是为了检查
$ python
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from petl imp
我之前已经做了一些关于这个错误的研究。这里有一些与StackOverflow相关的解释,虽然建议的解决方案是相当无关的。
当我尝试从gi.repository导入Gtk时,它崩溃了,输出如下:
`bash-4.2$ python3 Python 3.2 (r32:88445, Feb 21 2011, 21:11:06) [GCC 4.6.0 20110212 (Red Hat 4.6.0-0.7)] on linux2 Type "help", "copyright", "credits" or "licen
我希望返回一个文件的词小写没有标点符号。
尽管有目录str和bytes,但我无法在代码中导入这两种目录,而不会收到导入错误。导入字符串可以工作,即使python解释器说“没有定义‘name ' string’”
def text_to_words(the_text):
""" return a list of words with all punctuation removed,
and all in lowercase.
"""
my_substitutions = the_text.maket
如果我运行这个代码:
s.translate(str.maketrans({'as': 'dfg', '1234': 'qw'}))
我会得到:
ValueError: string keys in translate table must be of length 1
有办法一次用str.translate替换多个字符吗?Docs说我可以使用codecs实现灵活的方法,但我无法找到方法。
如果没有,那又能做些甚麽呢?
这个程序将加密一条消息。这将是一个凯撒版本的替代加密信息。它将把字母移到5.
from string import *
original = raw_input("Enter your string: ") # prompts user for their desired string
def sub(input, x):
alpha = string.ascii_lowercase
newAlpha = alpha[x:] + alpha[:x]
i = string.maketrans(alpha, newAlpha)
return in
import string
s = "Salut\n\tComment ca va ?"
t = str.maketrans("\n"," ")
y = str.maketrans("\t"," ")
#z = str.maketrans("\n\t"," ")
s = s.translate(t).translate(y) My Out > 'Salut Comment ca va ?' Expected > 'Salut Comment
1)如何将大写的A和小写的'a‘替换为数字1?
encrp_key = input('Enter the number 1' )
msg = input('Enter some lowercase and some uppercase')
if encrp_key == 1:
new_msg = msg.replace('a ','1').replace('e','2')\
当我尝试在Python 3.5.2 shell中运行命令时,收到以下错误:
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit
(Intel)] on win32 Type "copyright", "credits" or "license()" for more information.
>>> folder = 'C:/users/kdotz/desktop'
>>> f =
我有一个充满奇怪字符的文档,但我在另一个文档中有对应的信件。
例如:
⟷ = a
⇳ = b
⤚ = c
等等。
我认为我可以通过使用字典和简单的交换算法来做到这一点,但我仍然是编程方面的新手。你觉得这是个好主意吗?我如何翻译整个文本(最好使用Python或C++),而不必使用MS内置的“交换”工具?
我建立了一个非常基本的程序,该程序将接受英语输入,并使用不同语言的随机字母对其进行加密;并解密:-
def encrypt_decrypt():
inut = input("Text to convert ::-- ")
# feel free to replace the symbols ,, with ur own carecters or numbers or something
# u can also add numbers , and other carecters for encryption or decryption
decid
我正在尝试交换职位值。
a应该与e一起分配,反之亦然
b应该与g一起分配,反之亦然
有什么简单的方法吗?
我的代码:
str1="abcdefg"
clst=list(str1)
index_lst1=[]
index_lst2=[]
final_lst=[]
for i in range (len(clst)):
if clst[i] == 'a' or clst[i] == 'b':
index_lst1.append(i)
elif clst[i] == 'e' or clst[i] ==
我有下面的代码,并希望获得abc, cde作为输出。我尝试使用None将str(i or ' ') for i in m转换为空字符串,并将abc cde作为输出。是否可以隔离逗号,,以便输出为abc, cde?
d = {'1':'a', '2':'b', '3':'c', '4':'d', '5':'e'}
s = '123, 345'
m = [d.get(i) for i in s]
print(
运行python proxy.py时出现错误
$ python proxy.py
INFO - [Sep 28 14:59:19] getting appids from goagent plus common appid pool!
Traceback (most recent call last):
File "proxy.py", line 2210, in <module>
main()
File "proxy.py", line 2180, in main
pre_start()
File "proxy
我正在用python编写一个webapp来通过rot13转换字符串,比如rot13(a)=n,rot13(b)=o等等。但是代码只适用于后面的字母,从字母a到m,没有变化。我做错了什么,这是我的代码:
import webapp2
import cgi
form = """<form method="post">
Type a string to convert:
<br>
<textarea name="text">%(text)s</textarea>
我试着用Python把DNA代码转换成RNA代码..。
我写这个:
print('Digite a sequência DNA a ser transcrita para RNA:')
my_str = raw_input()
print(my_str.replace('T', 'U'))
而且很管用但是..。现在我需要把A转换成U,T转换成A,G到C,C到G.我看了看我是怎么做到的,就这样做了:
print('Digite a sequência DNA a ser transcrita para RNA:')
my_str
# Remove file extension and leading digits
file = filename.split('.')[0].lstrip(string.digits)
# Replace punctuation characters with underscores
# t = {ord(i) : '_' for i in string.punctuation}
file = file.translate(t) 对于上面的代码,我得到了如下错误: file = file.translate(t)
TypeError: expected a
我有一个python flask项目(程序),在那里我将用户输入的带有大写字母和标点符号的字符串转换成没有大写字母和标点符号的字符串。当我运行程序时,我得到了以下错误: ValueError: translation table must be 256 characters long
Traceback (most recent call last) File:
"/home/sd18656/.local/lib/python2.7/site-packages/flask/app.py", line
2463, in __call__ return self.wsgi_
在前面的程序中,我已经成功地创建了一个使用随机生成的偏移因子加密文本文件的代码,但我不知道如何将空格留在原处而不加密它们?
text_file = open("sample.txt", "r")
characters = []
for line in text_file:
for c in line:
characters.append(c)
text_ascii = []
text_number = 0
new_number = 0
cipher_text = ""
for i in characters:
text='hijklqrs'
def encrypt(shift_text,shift_amount, direction):
cipher_text=[]
for i in shift_text:
if direction is right:
cipher_text.append(text[(text.index(i) + shift_amount) % 26])
else:
以下是我想要做但却行不通的事情:
mystring = "hello world"
toUpper = ['a', 'e', 'i', 'o', 'u', 'y']
array = list(mystring)
for c in array:
if c in toUpper:
c = c.upper()
print(array)
"e"和"o"在我的数组中不是大写的。