小编Har*_*rma的帖子

使用python脚本将十六进制,八进制数转换为十进制形式

有许多inbulit函数,如int(八进制),可用于在命令行上将八进制数转换为十进制数,但这些在脚本中不起作用.int(0671)在脚本中返回0671,其中它表示python命令行上的八进制数的十进制形式.救命???

谢谢

python hex octal

4
推荐指数
1
解决办法
2万
查看次数

如何实现python在xml标签之间查找值?

我正在使用谷歌网站检索天气信息,我想在XML标签之间找到值.下面的代码给我一个城市的天气状况,但我无法获得其他参数,如温度,如果可能的话,解释代码中隐含的分离函数的工作:

import urllib

def getWeather(city):

    #create google weather api url
    url = "http://www.google.com/ig/api?weather=" + urllib.quote(city)

    try:
        # open google weather api url
        f = urllib.urlopen(url)
    except:
        # if there was an error opening the url, return
        return "Error opening url"

    # read contents to a string
    s = f.read()

    # extract weather condition data from xml string
    weather = s.split("<current_conditions><condition data=\"")[-1].split("\"")[0]

    # if there was an error getting the condition, the city is invalid


    if weather == "<?xml version=":
        return …
Run Code Online (Sandbox Code Playgroud)

python

3
推荐指数
1
解决办法
2992
查看次数

使用httplib使用python上传文件

conn = httplib.HTTPConnection("www.encodable.com/uploaddemo/")
conn.request("POST", path, chunk, headers)
Run Code Online (Sandbox Code Playgroud)

以上是我想要上传图片的网站"www.encodable.com/uploaddemo/".

我更精通,php所以我无法理解路径和标题的含义.在上面的代码中,chunk是一个由我的图像文件组成的对象.以下代码产生错误,因为我试图在不了解标头和路径的情况下实现.

import httplib

def upload_image_to_url():

    filename = '//home//harshit//Desktop//h1.jpg'
    f = open(filename, "rb")
    chunk = f.read()
    f.close()

    headers = {
        "Content?type": "application/octet?stream",
        "Accept": "text/plain"
    }

    conn = httplib.HTTPConnection("www.encodable.com/uploaddemo/")
    conn.request("POST", "/uploaddemo/files/", chunk)

    response = conn.getresponse()
    remote_file = response.read()
    conn.close()
    print remote_file

upload_image_to_url()
Run Code Online (Sandbox Code Playgroud)

python httplib

1
推荐指数
1
解决办法
9751
查看次数

标签 统计

python ×3

hex ×1

httplib ×1

octal ×1