我有3个API将json数据返回到3个字典变量.我从字典中取一些值来处理它们.我在列表中读到了我想要的具体值valuelist.其中一个步骤是从中删除标点符号.我通常string.translate(None, string.punctuation)用于此过程,但因为字典数据是unicode我得到错误:
wordlist = [s.translate(None, string.punctuation)for s in valuelist]
TypeError: translate() takes exactly one argument (2 given)
Run Code Online (Sandbox Code Playgroud)
有没有解决的办法?通过编码unicode或替换string.translate?
我在Ubuntu 12.04上安装了Virtualenv,并使用它来处理统一桌面下的示例项目.我正在使用VirtualBox,并且在Unity桌面上遇到了一些问题,因此改为KDE桌面.
我现在正在尝试创建一个新项目,但virtualenv不允许我在我的项目文件夹中创建一个新环境.在终端我导航到项目文件夹,键入virtualenv venv并获取以下错误消息:
Traceback (most recent call last):
File "/usr/bin/virtualenv", line 3, in <module>
virtualenv.main()
File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 938, in main
never_download=options.never_download)
File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 1039, in create_environment
site_packages=site_packages, clear=clear))
File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 1215, in install_python
copyfile(stdinc_dir, inc_dir)
File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 430, in copyfile
copyfileordir(src, dest)
File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 405, in copyfileordir
shutil.copytree(src, dest, True)
File "/usr/lib/python2.7/shutil.py", line 206, in copytree
raise Error, errors
shutil.Error: [('/usr/include/python2.7/numpy', 'venv/include/python2.7/numpy', '[Errno 30] Read-only file system')]
Run Code Online (Sandbox Code Playgroud)
谁能帮我解决这个问题?我已经尝试重新安装virtualenv但没有快乐.谢谢
如何在python中的单引号中包含变量?它可能很简单,但我似乎无法得到它!我需要对变量进行url编码term.Term由用户以表单形式输入,并传递给url编码的函数term=urllib.quote(term).如果用户输入"apple computer"作为他们的术语,则在url-encoding之后它将是"apple%20comptuer".我想要做的是在url编码之前使用单引号括起来的术语,以便在url-encoding"%23apple%20computer%23"之后它将是"'apple computer'".我需要将该术语传递给URL,除非我使用这种语法,否则它将无效.有什么建议?
示例代码:
import urllib2
import requests
def encode():
import urllib2
query= avariable #The word this variable= is to be enclosed by single quotes
query = urllib2.quote(query)
return dict(query=query)
def results():
bing = "https://api.datamarket.azure.com/Data.ashx/Bing/SearchWeb/Web?Query=%(query)s&$top=50&$format=json"
API_KEY = 'akey'
r = requests.get(bing % encode(), auth=('', API_KEY))
return r.json
Run Code Online (Sandbox Code Playgroud) 我正在尝试将值插入Oracle SQL中的"Employee"表.我有一个关于输入由外键确定的值的问题:
我的员工有3个由外键确定的属性:State,Position和Manager.我使用INSERT INTO语句插入值并手动键入数据.我是否需要在物理上查找每个引用以输入数据,或者是否有可以使用的命令?例如
INSERT INTO Employee
(emp_id, emp_name, emp_address, emp_state, emp_position, emp_manager)
VALUES
(001, "John Doe", "1 River Walk, Green Street", 3, 5, 1000)
Run Code Online (Sandbox Code Playgroud)
这应该填充employee表(John Doe, 1 River Walk, Green Street, New York, Sales Executive, Barry Green).纽约state_id=3在State桌子上; 销售主管position_id=5在positions谈判桌上; 和巴里格林manager_id=1000在manager桌子上.
有没有办法可以输入引用表的文本值,以便Oracle识别文本并将其与相关ID匹配?我希望这个问题有意义,很乐意澄清任何事情.
谢谢!
我之前已经知道有关此问题的各种问题,但我找不到我的问题的答案.我正在开发一个Android应用程序,我希望EditText字段在用户输入时扩展.我希望它首先是最小尺寸,如果用户输入的数量超过最小允许值,则扩展.到目前为止,这是我的代码:
<ScrollView
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:fillViewport="true" >
<linearLayout
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:orientation="vertical"
android:padding="5dp" >
<linearLayout>
...content...
</linearLayout>
<linearLayout>
...content...
</linearLayout>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:lines="7"
android:gravity="top" />
</linearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
EditText字段位于父级ScrollView内的父linearLayout内.它在屏幕上看起来很好但是当我在编辑文本字段中超过第7行时,我必须使用轨迹球返回文本字段.滚动屏幕会滚动整个屏幕.谁能给我一些提示?我尝试对类似的问题实施不同的建议,但没有一个给我正确的答案.谢谢
自从我升级Android Tools到21.1 后出现此问题.当我开始eclipse时,即使在干净的工作空间中,我也会收到错误parseSdkContent failed,并且详细说明:
com.android.sdklib.devices.DeviceManager.createInstance
(Ljava/lang/String;Lcom/android/utils/ILogger;)
Lcom/android/sdklib/devices/DeviceManager;
Run Code Online (Sandbox Code Playgroud)
我已经搜索了互联网并尝试了几乎所有解决方案但无济于事.当我转到Android偏好设置并尝试设置SDK的路径时,它表示没有可用的目标.还有什么我可以尝试的吗?在修复之前我无法进行任何Android开发.
在python中,我想向一个url发送一个请求,它会向我返回一些信息.问题是如果我尝试从浏览器访问URL,则会出现一个弹出框并要求输入用户名和密码.我有这个URL的用户名和密码,但是,我不知道如何让python自动完成这些字段来访问URL.
这是我的代码返回401错误:
bing = "https://api.datamarket.azure.com/Data.ashx/Bing/SearchWeb/Web?Query=%
(term)s&$top=50&$format=json" %__function()
results = urllib2.urlopen(bing).read()
Run Code Online (Sandbox Code Playgroud)
编辑:只是为了澄清,该函数function返回一个名为变量的变量,该变量term在URL中被查询
我有一个从json数据创建的大型python dict,我正在创建一个较小的dict.大字典的一些元素有一个称为"细节"的键,而一些元素则没有.我想要做的是检查大字典中的每个条目中是否存在密钥,如果不存在,请将具有值"No details available"的密钥"details"附加到新字典中.我在下面放一些示例代码作为演示.在我的代码中有很多键的LargeDict要大得多,但为了清晰起见,我保持简单.
LargeDict = {'results':
[{'name':'john','age':'23','datestart':'12/07/08','department':'Finance','details':'Good Employee'},
{'name':'barry','age':'26','datestart':'25/08/10','department':'HR','details':'Also does payroll'},
{'name':'sarah','age':'32','datestart':'13/05/05','department':'Sales','details':'Due for promotion'},
{'name':'lisa','age':'21','datestart':'02/05/12','department':'Finance'}]}
Run Code Online (Sandbox Code Playgroud)
这就是我获取SmallDict数据的方式:
SmallDict = {d['name']:{'department':d['department'],'details':d['details']} for d in LargeDict['results']}
Run Code Online (Sandbox Code Playgroud)
我得到一个关键错误,但是当一个大的dict条目没有细节时.我说得对,我需要使用DefaultDict模块,还是有更简单的方法?
我在这里看不到问题,这让我感到疯狂.我正在循环浏览2个文本文件.每个文件中的某些行匹配,有些则不匹配.我正在做的是循环file1.对于该文件中的每一行,循环遍历file2并比较每个元素以查看它们是否相同.发生的事情是我的循环在第一次循环通过file1后停止.这是我的代码:
while f < 50:
for line in file1:
for name in file2:
if name == line:
print 'a match was found'
f+=1
Run Code Online (Sandbox Code Playgroud)
while循环来自其他地方,但它工作正常.我只是把它包含在上下文中.问题是file1只给我第一行,将它与file2中的所有'名称'进行比较然后停止而不是重复file1中下一行的进程.我错过了一些明显的东西吗?
编辑:如果我在第一个for循环之后放入一个print语句并注释掉另一个for循环,它将遍历整个第一个文件
我不明白为什么这不起作用.我正在测试的Web应用程序有一个弹出框,单击按钮时会生成该框.此弹出框包含一个表,其每一行都是可单击的.我已经尝试了许多Actions,表行选择等实现,但没有任何工作.该元素对Selenium是可见的,它不会单击它.也没有抛出任何错误.
附加注意:我已经使用其他元素检查了Action方法,并且它可以工作,因此它必须是正在使用的选择器或它是如何看到它的.非常奇怪的行为.我已经在Firefox中使用Selenium IDE检查了它,weblement.click()将在CSS选择器上使用它.
public class ContactDetails {
WebDriver driverInstance;
public ContactDetails(WebDriver driver){
this.driverInstance = driver;
}
public void enterContactDetails(){
//Other code here...
By validAddress = By.cssSelector("#customerAddress > tbody > tr:nth-child(1) > td");
//Validate that the element is visible. Definitely working as intended because I use it elsewhere in the code successfully.
if (Helper.checkElementVisible(driverInstance, validAddress)){
//if visible:
WebElement selectAddress = driverInstance.findElement(validAddress);
//Helper.scrollToElementAndClick(driverInstance, selectAddress);
Actions actions = new Actions(driverInstance);
actions.moveToElement(selectAddress).click().perform();
}
}
}
Run Code Online (Sandbox Code Playgroud)
助手班级:
public class Helper {
public static void scrollToElementAndClick(WebDriver …Run Code Online (Sandbox Code Playgroud) python ×6
android ×2
dictionary ×2
action ×1
adt ×1
eclipse ×1
file-io ×1
for-loop ×1
insert-into ×1
java ×1
oracle ×1
selenium ×1
sql ×1
symlink ×1
unicode ×1
virtualbox ×1
virtualenv ×1
xml ×1