对于最近提出的问题,我开始怀疑是否有一种非常简单的方法来处理Python中的XML文档.一种pythonic方式,如果你愿意的话.
如果我举一个例子,也许我可以解释得最好:让我们说以下 - 我认为这是一个很好的例子,说明如何(错误地)在Web服务中使用XML - 是我从http请求到http://www.google的回复的.com/IG/API?天气= 94043
<xml_api_reply version="1">
<weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0" >
<forecast_information>
<city data="Mountain View, CA"/>
<postal_code data="94043"/>
<latitude_e6 data=""/>
<longitude_e6 data=""/>
<forecast_date data="2010-06-23"/>
<current_date_time data="2010-06-24 00:02:54 +0000"/>
<unit_system data="US"/>
</forecast_information>
<current_conditions>
<condition data="Sunny"/>
<temp_f data="68"/>
<temp_c data="20"/>
<humidity data="Humidity: 61%"/>
<icon data="/ig/images/weather/sunny.gif"/>
<wind_condition data="Wind: NW at 19 mph"/>
</current_conditions>
...
<forecast_conditions>
<day_of_week data="Sat"/>
<low data="59"/>
<high data="75"/>
<icon data="/ig/images/weather/partly_cloudy.gif"/>
<condition data="Partly Cloudy"/>
</forecast_conditions>
</weather>
</xml_api_reply>
Run Code Online (Sandbox Code Playgroud)
在加载/解析这样的文档之后,我希望能够像访问那样简单地访问信息 …
好的,我有一堆球:
我想弄清楚的是如何制作这些圈子:
根据他们接触的表面旋转
处理多个触摸物体时修复碰撞穿透.
编辑:这就是我所说的旋转
球0将旋转逆时针,因为它是扶着球3
球5将旋转顺时针方向,因为它是扶着球0
即使这个解决方案是通用的,只是为了记录我使用Javascript和SVG,并且更愿意自己实现这个而不是使用库.
非常感谢帮助.谢谢!:)
功能编程..就像经典(马克吐温的类型).在阅读另一篇关于SICP的文章时,人们在谈论闭包对思维的影响,我得到了提醒,我读过很久以前
关闭是穷人的对象对象是穷人的关闭
(不记得确切的来源,但它是程序员,或编程的禅,或编程的tau ...谷歌已经变得如此拥挤,不能去原始来源)
所以共同编程人员......你有什么看法......关闭你总是缺少的东西......或者只是一些语法糖,这是一个预处理器可以做到的!
我必须将我的if语句设置为
if(Test == "test1" || Test == "test2" || Test == "test3")
{
//do something
}
Run Code Online (Sandbox Code Playgroud)
有没有办法有类似的东西
if(Test == "test1":"test2":"test3")
Run Code Online (Sandbox Code Playgroud) 最近我反复讨论LFSR的概念,我发现它非常有趣,因为它与不同的领域有联系并且本身也很吸引人.我花了一些力气去理解,最后的帮助是这个非常好的页面,比(起初)神秘的维基百科条目要好得多.所以我想为一个像LFSR一样工作的程序编写一些小代码.更确切地说,它以某种方式展示了LFSR的工作原理.这是在经过一些长篇尝试(Python)之后我能想到的最干净的东西:
def lfsr(seed, taps):
sr, xor = seed, 0
while 1:
for t in taps:
xor += int(sr[t-1])
if xor%2 == 0.0:
xor = 0
else:
xor = 1
print xor
sr, xor = str(xor) + sr[:-1], 0
print sr
if sr == seed:
break
lfsr('11001001', (8,7,6,1)) #example
Run Code Online (Sandbox Code Playgroud)
我将XOR函数的输出命名为"xor",不是很正确.但是,这只是为了说明它如何圈出其可能的状态,实际上您注意到寄存器由字符串表示.没有多少逻辑连贯性.
这可以很容易地变成一个你可以看几个小时的好玩具(至少我可以:-)
def lfsr(seed, taps):
import time
sr, xor = seed, 0
while 1:
for t in taps:
xor += int(sr[t-1])
if xor%2 == 0.0:
xor = 0 …
Run Code Online (Sandbox Code Playgroud) 我知道如何创建振动模式,例如:
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
long pattern[] = new long[] {0, 200, 100, 200};
vibrator.vibrate(pattern, -1);
Run Code Online (Sandbox Code Playgroud)
但我不知道哪种模式会传达"错误输入".是否有任何指导方针或预定义模式?
编辑:似乎我的问题有点令人困惑.我的意思是,有些声音可以识别成功或失败,它们很常见.但是,是否存在可用于成功或失败的振动模式,大多数人都会理解?
最终我得到了答案,但它让我困惑了一段时间.
为什么以下代码在运行时抛出NullPointerException?
import java.util.*;
class WhyNullPointerException {
public static void main( String [] args ){
// Create a map
Map<String,Integer> m = new HashMap<String,Integer>();
// Get the previous value, obviously null.
Integer a = m.get( "oscar" );
// If a is null put 1, else increase a
int p = a == null ?
m.put( "oscar", 1) :
m.put( "oscar", a++ ); // Stacktrace reports Npe in this line
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用以下python代码将元数据写入pdf文件:
from Foundation import *
from Quartz import *
url = NSURL.fileURLWithPath_("test.pdf")
pdfdoc = PDFDocument.alloc().initWithURL_(url)
assert pdfdoc, "failed to create document"
print "reading pdf file"
attrs = {}
attrs[PDFDocumentTitleAttribute] = "THIS IS THE TITLE"
attrs[PDFDocumentAuthorAttribute] = "A. Author and B. Author"
PDFDocumentTitleAttribute = "test"
pdfdoc.setDocumentAttributes_(attrs)
pdfdoc.writeToFile_("mynewfile.pdf")
print "pdf made"
Run Code Online (Sandbox Code Playgroud)
这似乎工作正常(安慰没有错误),但是当我检查文件的元数据时,它如下:
PdfID0:
242b7e252f1d3fdd89b35751b3f72d3
PdfID1:
242b7e252f1d3fdd89b35751b3f72d3
NumberOfPages: 4
Run Code Online (Sandbox Code Playgroud)
原始文件具有以下元数据:
InfoKey: Creator
InfoValue: PScript5.dll Version 5.2.2
InfoKey: Title
InfoValue: Microsoft Word - PROGRESS ON THE GABION HOUSE Compressed.doc
InfoKey: Producer
InfoValue: GPL Ghostscript …
Run Code Online (Sandbox Code Playgroud) 我从谷歌收到了这封邮件......
您好,您的Google云端平台项目:Google Play Android Developer已经处于禁用状态状态超过30天.由于Google Compute Engine需要有效的结算帐户,因此计划在7天内删除所有相关的Google Compute Engine资源.
请注意,您的Google Cloud Platform项目不会被删除,其他不依赖于Google Compute Engine资源的服务也不会受到影响.
如果您在7天内未采取任何措施,则无法在此项目中恢复Google Compute Engine下的任何资源.如果无意中禁用了结算,请按照在线说明a在7天内重新启用此项目的结算,以避免资源被删除.
如果您有任何疑问,请访问项目计费帮助页面或通过以下链接联系支持.
这是什么意思?7天后我的开发者帐户是否被删除?我是否需要再次支付25美元的注册费?我从来没有使用云服务然后谷歌发送给我这封邮件.请帮忙 ...