python-2.4

XML to/from a Python dictionary

余生颓废 提交于 2019-12-03 16:41:48
I need to use Python 2.4.4 to convert XML to and from a Python dictionary. All I need are the node names and values, I'm not worried about attributes because the XML I'm parsing doesn't have any. I can't use ElementTree because that isn't available for 2.4.4, and I can't use 3rd party libraries due to my work environment. What's the easiest way for me to do this? Are there any good snippets? Also, if there isn't an easy way to do this, are there any alternative serialization formats that Python 2.4.4 has native support for? Grey Teardrop Question Serialize Python dictionary to XML lists some

SMTP AUTH extension not supported by server in python 2.4

半世苍凉 提交于 2019-12-03 11:56:23
问题 This is my normal code in my VPS hosting which provide python 2.4 def mail(receiver,Message): import smtplib try: s=smtplib.SMTP() s.connect("smtp.gmail.com",465) s.login("email@gmail.com", "password") s.sendmail("email@gmail.com", receiver, Message) except Exception,R: return R but unfortunately return this message! : SMTP AUTH extension not supported by server. in my computer which i've install python 2.7 i found the solution and it's work very good here is this code : def mail(T,M): import

In Python 2.4, how can I strip out characters after ';'?

狂风中的少年 提交于 2019-12-03 09:23:08
Let's say I'm parsing a file, which uses ; as the comment character. I don't want to parse comments. So if I a line looks like this: example.com. 600 IN MX 8 s1b9.example.net ; hello! Is there an easier/more-elegant way to strip chars out other than this: rtr = '' for line in file: trig = False for char in line: if not trig and char != ';': rtr += char else: trig = True if rtr[max(rtr)] != '\n': rtr += '\n' I'd recommend saying line.split(";")[0] which will give you a string of all characters up to but not including the first ";" character. If no ";" character is present, then it will give you

Python ConfigParser interpolation from foreign section

折月煮酒 提交于 2019-12-03 06:01:12
With Python ConfigParser, is it possible to use interpolation across foreign sections? My mind seems to tell me I've seen that it's possible somewhere, but I can't find it when searching. This example doesn't work, but it's to give an idea of what I'm trying to do. [section1] root = /usr [section2] root = /usr/local [section3] dir1 = $(section1:root)/bin dir2 = $(section2:root)/bin Note that I'm using Python 2.4. chown In python 3.2 and up this is perfectly valid: [Common] home_dir: /Users library_dir: /Library system_dir: /System macports_dir: /opt/local [Frameworks] Python: 3.2 path: $

SMTP AUTH extension not supported by server in python 2.4

微笑、不失礼 提交于 2019-12-03 02:20:44
This is my normal code in my VPS hosting which provide python 2.4 def mail(receiver,Message): import smtplib try: s=smtplib.SMTP() s.connect("smtp.gmail.com",465) s.login("email@gmail.com", "password") s.sendmail("email@gmail.com", receiver, Message) except Exception,R: return R but unfortunately return this message! : SMTP AUTH extension not supported by server. in my computer which i've install python 2.7 i found the solution and it's work very good here is this code : def mail(T,M): import smtplib try: s=smtplib.SMTP_SSL() s.connect("smtp.gmail.com",465) s.login("xxxxx@gmail.com","your

JSON module for python 2.4?

你说的曾经没有我的故事 提交于 2019-12-03 01:31:11
I'm accustomed to doing import json in Python 2.6, however I now need to write some code for Python 2.4. Is there a JSON library with a similar interface that is available for Python 2.4? The json module in Python 2.6 is mostly the same as the simplejson third-party module, which is available for Python 2.4 as well. You can just do: try: import json except ImportError: import simplejson as json Now, a few years later, simplejson does only support python 2.5+. No more simplejson for systems stuck on 2.4. Even though it is not supported, you may find older packages on pypi. 2.0.9 or 2.1.0 should

TypeError: __init__() takes exactly 1 argument (3 given) pyXML

不羁的心 提交于 2019-12-01 21:17:21
问题 I've recently started to learn how to use python to parse xml files. I took the tutorial from http://pyxml.sourceforge.net/topics/howto/node12.html When I run the following code I get the error: Traceback (most recent call last): File "C:\Users\Name\Desktop\pythonxml\tutorials\pythonxml\pyxml sourceforge\5.1 Comic Colection\SearchForComic.py", line 30, in -toplevel- dh = FindIssue('sandman', '62') TypeError: __init__() takes exactly 1 argument (3 given) code: from xml.sax import saxutils

TypeError: __init__() takes exactly 1 argument (3 given) pyXML

末鹿安然 提交于 2019-12-01 19:41:46
I've recently started to learn how to use python to parse xml files. I took the tutorial from http://pyxml.sourceforge.net/topics/howto/node12.html When I run the following code I get the error: Traceback (most recent call last): File "C:\Users\Name\Desktop\pythonxml\tutorials\pythonxml\pyxml sourceforge\5.1 Comic Colection\SearchForComic.py", line 30, in -toplevel- dh = FindIssue('sandman', '62') TypeError: __init__() takes exactly 1 argument (3 given) code: from xml.sax import saxutils class FindIssue(saxutils.DefaultHandler): def __init___(self, title, number): self.search_title, self

Interpreting Strings as Other Data Types in Python

不羁的心 提交于 2019-12-01 06:05:20
I'm reading a file into python 2.4 that's structured like this: field1: 7 field2: "Hello, world!" field3: 6.2 The idea is to parse it into a dictionary that takes fieldfoo as the key and whatever comes after the colon as the value. I want to convert whatever is after the colon to it's "actual" data type, that is, '7' should be converted to an int , "Hello, world!" to a string, etc. The only data types that need to be parsed are ints, floats and strings. Is there a function in the python standard library that would allow one to make this conversion easily? The only things this should be used to

Handling months in python datetimes

做~自己de王妃 提交于 2019-12-01 06:01:19
问题 I have a function which gets the start of the month before the datetime provided: def get_start_of_previous_month(dt): ''' Return the datetime corresponding to the start of the month before the provided datetime. ''' target_month = (dt.month - 1) if target_month == 0: target_month = 12 year_delta = (dt.month - 2) / 12 target_year = dt.year + year_delta midnight = datetime.time.min target_date = datetime.date(target_year, target_month, 1) start_of_target_month = datetime.datetime.combine