我有一个python脚本,必须为dir中的每个文件启动一个shell命令:
import os
files = os.listdir(".")
for f in files:
os.execlp("myscript", "myscript", f)
Run Code Online (Sandbox Code Playgroud)
这适用于第一个文件,但在"myscript"命令结束后,执行停止并且不会返回到python脚本.
我能怎么做?我fork()以前需要calling os.execlp()吗?
旋转设备时,是否可以避免在Safari for iOS中过渡到横向视图?
iOS Safari有"orentationchange"事件,我试图拦截它并禁用默认行为,如下所示:
<html>
<head>
<script type="text/javascript">
function changeOrientation(event) {
alert("Rotate");
event.preventDefault();
}
</script>
</head>
<body onorientationchange="changeOrientation(event);">
PAGE CONTENT
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
但是当我在iPhone上测试页面时,当我旋转设备时会显示警报,但视图会切换到横向.似乎event.preventDefault()不会停止旋转.
有没有办法阻止这种行为?
我正在编写一个使用pdfbox库从头开始创建pdf的Java应用程序.
我需要在页面中放置一个jpg图像.
我正在使用此代码:
PDDocument document = new PDDocument();
PDPage page = new PDPage(PDPage.PAGE_SIZE_A4);
document.addPage(page);
PDPageContentStream contentStream = new PDPageContentStream(document, page);
/* ... */
/* code to add some text to the page */
/* ... */
InputStream in = new FileInputStream(new File("c:/myimg.jpg"));
PDJpeg img = new PDJpeg(document, in);
contentStream.drawImage(img, 100, 700);
contentStream.close();
document.save("c:/mydoc.pdf");
Run Code Online (Sandbox Code Playgroud)
当我运行代码时,它会成功终止,但是如果我使用Acrobat Reader打开生成的pdf文件,页面将完全为白色,并且图像不会放入其中.
而是将文本正确放置在页面中.
有关如何将我的图像放入pdf的任何提示?
编辑:我想我已经弄清楚如何做二进制数据部分.在代码中仔细检查它,但我很确定我做对了.现在,我在尝试按照Vimeo API文档中的描述完成上传时遇到了新错误
编辑2:将 .debug()添加到OAuthService并更新输出.
原始问题:我正在尝试使用Vimeo API(流媒体方法)将视频上传到Vimeo .我正在使用scribe来授权我的应用,获取我的访问令牌并准备上传视频.在这个PUT的HTTP请求示例中,我只是不知道该做什么,Vimeo API文档说"你这里的文件的二进制数据":
PUT http://1.2.3.4:8080/upload?ticket_id=abcdef124567890 HTTP/1.1
主持人:1.2.3.4:8080
内容长度:339108
内容类型:video/mp4
....你的文件的二进制数据在这....
我可以得到罚单和标题.它只是,我该怎么做才能插入我的文件的二进制数据?
笔记:
这是我的put代码(记住,我正在使用scribe)
// Setup File (line 52)
File testUp = new File("C:/Users/Kent/Desktop/test.mp4");
String contentLength = Long.toString(testUp.length());
System.out.println("The content length is: " + contentLength);
byte[] fileBytes = ByteStreams.toByteArray(new FileInputStream(testUp));
// Upload file (line 58)
request = new OAuthRequest(Verb.PUT, endpoint);
request.addHeader("Content-Length", contentLength);
request.addHeader("Content-Type", "video/mp4");
request.addPayload(fileBytes);
response = signSendAndPrint(service, accessToken, request, "Upload PUT: " + …Run Code Online (Sandbox Code Playgroud) 我正在使用NetBeans中的Java和Swing构建一个小应用程序.使用NetBeans设计窗口,我在里面创建了一个带有JPanel的JFrame.
现在我想动态地将一些jTextField添加到JPanel.我写了类似的东西:
Vector textFieldsVector = new Vector();
JTextField tf;
int i = 0;
while (i < 3) {
tf = new JTextField();
textFieldVector.add(tf);
myPanel.add(tf); //myPanel is the JPanel where I want to put the JTextFields
i++;
}
myPanel.validate();
myPanel.repaint();
Run Code Online (Sandbox Code Playgroud)
但没有任何反应:当我运行应用程序时,JFrame显示内部的JPanel,但JTextFields没有.
我是编写图形Java应用程序的新手,所以我肯定错过了一些非常简单的东西,但我看不出是什么.
如果我使用php和mysqli _*函数执行带有存储过程的插入查询,有没有办法检索autoincrement id字段的值?
mysqli->insert_id似乎不起作用.
我正在构建一个小的Chrome扩展程序,它必须通过POST http请求将消息发送到我公司网络中的服务器,并且我正在使用jQuery 1.4.1来加速javascript部分的开发.
我有这个代码发送请求:
function send() {
$.ajax({
url: "http://mycompany.com/update",
method: "POST",
data: {status: "sometest", in_reply_to_status_id: "anId"},
success: function(data, textStatus) {
console.log("success");
console.log(data);
console.log(textStatus);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.log("error");
console.log(XMLHttpRequest);
console.log(textStatus);
console.log(errorThrown);
},
complete: function(XMLHttpRequest, textStatus) {
console.log("complete");
}
});
}
Run Code Online (Sandbox Code Playgroud)
以这种方式执行的请求失败,在Chrome日志中,我看到服务器以http状态400响应并且文本"此方法需要POST".
如果我改为上面的代码:
function send() {
$.post("http://sunshine.emerasoft.com/statusnet/api/statuses/update.xml", {status: "sometext", in_reply_to_status_id: "anId"}, function(data) {
console.log(data)
});
}
Run Code Online (Sandbox Code Playgroud)
一切正常,http状态为200,服务器端我可以看到我发送的数据已正确保存.
我需要使用完整的$ .ajax()方法,因为我需要在成功或失败的情况下做一些工作,而在请求完成时需要做其他工作,所以$ .post()是不够的.
我是否在调用$ .ajax()时出错了,或者存在某种问题,可能是因为我在Chrome扩展程序的xontext中?
谢谢
我已经在OS X 10.6.3下的Eclipse(3.5.1)中成功安装了最新版本的PyDev,使用python 2.6.1
我在安装我已安装的库时遇到了麻烦.
例如,我正在尝试使用cx_Oracle库,如果从使用某些文本编辑器创建的简单脚本的python interpeter调用,则该库非常有效.
但我不能让它在Eclipse中运行:我有一小段代码:
import cx_Oracle
conn = cx_Oracle.connect(CONN_STRING)
sql = "select field from mytable"
cursor = conn.cursor()
cursor.execute(sql)
for row in cursor:
field = row[0]
print field
Run Code Online (Sandbox Code Playgroud)
如果我从Eclipse执行它,我会收到以下错误:
import cx_Oracle
File "build/bdist.macosx-10.6-universal/egg/cx_Oracle.py", line 7, in <module>
File "build/bdist.macosx-10.6-universal/egg/cx_Oracle.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/dave/.python-eggs/cx_Oracle-5.0.3-py2.6-macosx-10.6-universal.egg-tmp/cx_Oracle.so, 2): Library not loaded: /b/227/rdbms/lib/libclntsh.dylib.10.1
Referenced from: /Users/dave/.python-eggs/cx_Oracle-5.0.3-py2.6-macosx-10.6-universal.egg-tmp/cx_Oracle.so
Reason: no suitable image found. Did find:
/Users/dave/lib/libclntsh.dylib.10.1: mach-o, but wrong architecture
Run Code Online (Sandbox Code Playgroud)
相同的代码段完全可以从python shell中运行
我在偏好中配置了Eclipse中的interpeter - > PyDev - > Interpreter - Python,使用Auto …
假设我有以下XML文件:
<?xml version="1.0" encoding="utf-8"?>
<venues>
<group type="Nearby">
<venue>
<id>222307</id>
<name>Union Chapel</name>
<primarycategory>
<id>78967</id>
<fullpathname>Arts & Entertainment:Music Venue</fullpathname>
<nodename>Music Venue</nodename>
<iconurl>http://foursquare.com/img/categories/arts_entertainment/musicvenue.png</iconurl>
</primarycategory>
<address>Compton Ave</address>
<city>Islington</city>
<state>Greater London</state>
<zip>N1 2XD</zip>
<verified>false</verified>
<geolat>51.5439732</geolat>
<geolong>-0.1020908</geolong>
<stats>
<herenow>0</herenow>
</stats>
<phone>02073594019</phone>
<distance>33</distance>
</venue>
Run Code Online (Sandbox Code Playgroud)
.............
我的代码如下:
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
XPathExpression expr = xpath.compile("//venue/*");
Object result = expr.evaluate(document, XPathConstants.NODESET);
NodeList nodes = (NodeList) result;
//System.out.println(nodes.getLength());
Venue ven = new Venue();
for (int i = 0; i < nodes.getLength(); i++) {
String nodeName = …Run Code Online (Sandbox Code Playgroud) 我尝试并试图让这个代码工作,并继续提出zilch.所以我决定尝试使用"for loops"而不是它首先尝试.有人能告诉我为什么这段代码不好?
<?php
$x = $y = 10;
while ($x < 100) {
while ($y < 100) {
$num = $x * $y;
$numstr = strval($num);
if ($numstr == strrev($numstr)) {
$pals[] = $numstr;
}
$y++;
}
$x++;
}
?>
Run Code Online (Sandbox Code Playgroud) 我有一个像这样的xml文件:
<car>Ferrari</car>
<color>red</color>
<speed>300</speed>
<car>Porsche</car>
<color>black</color>
<speed>310</speed>
Run Code Online (Sandbox Code Playgroud)
我需要以这种形式:
<car name="Ferrari">
<color>red</color>
<speed>300</speed>
</car>
<car name="Porsche">
<color>black</color>
<speed>310</speed>
</car>
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?我正在努力,因为我想不出一种方法来创建我需要的结构,从原始xml文件中的平面标签lis.
我选择的语言是Python,但欢迎提出任何建议.
有人能告诉我这个python代码出了什么问题吗?看起来很傻,因为代码非常简单,但我是编码的初学者,希望可以理解.
f = open("countries.txt", "r")
countries = []
for line in f:
line = line.strip()
countries.append(line)
f.close()
print(countries)
print(len(countries))
for country in countries:
if country[0] == "T":
print(country)
Run Code Online (Sandbox Code Playgroud)
我一直收到以下错误:
line 16, in <module>
if country[0] == "T":
IndexError: string index out of range
Run Code Online (Sandbox Code Playgroud) java ×4
python ×4
javascript ×2
php ×2
ajax ×1
eclipse ×1
file-upload ×1
html ×1
http-put ×1
ios ×1
jpanel ×1
jquery ×1
jtextfield ×1
mysql ×1
mysqli ×1
nested ×1
orientation ×1
os.execl ×1
pdf ×1
pdfbox ×1
popen ×1
pydev ×1
python-3.x ×1
safari ×1
scribe ×1
subprocess ×1
swing ×1
vimeo ×1
while-loop ×1
xml ×1
xpath ×1