time.perf_counter in Python 2?

2014-10-20 Thread Florian Lindner
Hello, I wrote a script that does some time measurements. It uses time.perf_counter() from Python 3 which works very well. Now I need to backport it to python 2. Docs say that time.clock() is way to go: time.clock() On Unix, return the current processor time as a floating point number

Why is regexp not working?

2014-07-04 Thread Florian Lindner
Hello, I have that piece of code: def _split_block(self, block): cre = [re.compile(r, flags = re.MULTILINE) for r in self.regexps] block = .join(block) print(block) print(---) for regexp in cre: match = regexp.match(block)

Get named groups from a regular expression

2014-07-01 Thread Florian Lindner
Hello, Is there a way I can extract the named groups from a regular expression? e.g. given (?Ptestgrp\d) I want to get something like [testgrp]. OR Can I make the match object to return default values for named groups, even if no match was produced? Thanks, Florian --

Format String: Only when value supplied

2014-06-24 Thread Florian Lindner
Hello, I have a format string like: print {:10} {:25} = {:6} ({}).format(mod, name, value, description) description can be None. In this case I want to print an empty string (which can be achieved by replacing it with 'description or ') and I want to omit the brackets. Is there a way to

Encoding trouble when script called from application

2014-01-14 Thread Florian Lindner
Hello! I'm using python 3.2.3 on debian wheezy. My script is called from my mail delivery agent (MDA) maildrop (like procmail) through it's xfilter directive. Script works fine when used interactively, e.g. ./script.py testmail but when called from maildrop it's producing an infamous

Re: python-list@python.org

2014-01-14 Thread Florian Lindner
Am Dienstag, 14. Januar 2014, 17:00:48 schrieb MRAB: On 2014-01-14 16:37, Florian Lindner wrote: Hello! I'm using python 3.2.3 on debian wheezy. My script is called from my mail delivery agent (MDA) maildrop (like procmail) through it's xfilter directive. Script works fine when

Trouble with UnicodeEncodeError and email

2014-01-08 Thread Florian Lindner
Hello! I've written some tiny script using Python 3 and it used to work perfectly. Then I realized it needs to run on my Debian Stable server too, which offers only Python 2. Ok, most backporting was a matter of minutes, but I'm becoming desperate on some Unicode error... i use scikit-learn

Re: Trouble with UnicodeEncodeError and email

2014-01-08 Thread Florian Lindner
Am Donnerstag, 9. Januar 2014, 00:26:15 schrieb Chris Angelico: On Thu, Jan 9, 2014 at 12:14 AM, Florian Lindner mailingli...@xgm.de wrote: I've written some tiny script using Python 3 and it used to work perfectly. Then I realized it needs to run on my Debian Stable server too, which

argparse action on default values

2014-01-08 Thread Florian Lindner
Hello, I use argparse from Python 3.3.3 with a custom action that normalizes path arguments: http://docs.python.org/3/library/argparse.html#action def norm_path(*parts): Returns the normalized, absolute, expanded and joined path, assembled of all parts. parts = [ str(p) for p in

Flattening an email message

2013-11-26 Thread Florian Lindner
Hello, I want to use some machine learning stuff on mail messages. First step is get some flattened text from a mail message, python's email package does not work as automatically as I wish. Right now I have: def mail_preprocessor(str): msg = email.message_from_string(str) msg_body

Problem calling script with arguments

2013-10-15 Thread Florian Lindner
Hello, I have a 3rd party perl script: head -n 1 /usr/sbin/ftpasswd #!/usr/bin/perl I want to write data to stdin and read from stdout: proc = Popen( [/usr/bin/perl, /usr/sbin/ftpasswd --hash, --stdin], stdout=PIPE, stdin=PIPE) output, input = proc.communicate(pwd) return output.strip()

Re: Problem calling script with arguments

2013-10-15 Thread Florian Lindner
Am Dienstag, 15. Oktober 2013, 13:18:17 schrieb Michael Speer: /usr/sbin/ftpasswd --hash You're missing a comma, and python automatically concatenates adjacent strings. Damn! Thanks! On Tue, Oct 15, 2013 at 1:13 PM, Florian Lindner mailingli...@xgm.dewrote: Hello, I have a 3rd

Using inner dict as class interface

2013-01-16 Thread Florian Lindner
Hello, I have a: class C: def __init__(self): d = dict_like_object_created_somewhere_else() def some_other_methods(self): pass class C should behave like a it was the dict d. So I could do: c = C() print c[key] print len(c) but also c.some_other_method() How can I achieve

Logging handler: No output

2012-09-02 Thread Florian Lindner
Hello, I have a class method that executes a subprocess. There are two loggers in the class, self.logger for general logging and proclog for process output (stdout stderr) logging which should go to stdout and a file: def start_process(self, command, no_shlex=False, raise_excpt=True,

XML parser: Element ordering?

2012-08-31 Thread Florian Lindner
Hello, I plan to use the etree.ElementTree XML parser to parse a config file in which the order of the elements matter, e.g.: A C /D / /A is not equal to: A D /C / /A I have found different answers to the question if order matters in XML documents. So my question here: Does it matters (and is

Cut out XML subtree

2012-08-29 Thread Florian Lindner
Hello, I have a (rather small, memory consumption is not an issue) XML document. The application is still at the planning stage, so none of the XML parsers from the stdlib is choosen yet. I want to cut out an XML subtree like that: root attribute=foobar subA some_more_elements / /subA

Remove root handler from logger

2012-05-14 Thread Florian Lindner
Hello, I configure my logging on application startup like that: logging.basicConfig(level = logging.DEBUG, format=FORMAT, filename = logfile) ch = logging.StreamHandler() ch.setFormatter(logging.Formatter(FORMAT)) logging.getLogger().addHandler(ch) In one module of my application I want a

tee-like behavior in Python

2012-05-09 Thread Florian Lindner
Hello, how can I achieve a behavior like tee in Python? * execute an application * leave the output to stdout and stderr untouched * but capture both and save it to a file (resp. file-like object) I have this code proc = subprocess.Popen(shlex.split(cmd), stdout = subprocess.PIPE,

Re: Avoid newline at the end

2007-11-11 Thread Florian Lindner
Steven D'Aprano wrote: On Sun, 11 Nov 2007 11:22:19 +0100, Florian Lindner wrote: Hello, I have a piece of code like that: for row in resultSet: logs += /home/%s/%s/log/access.log \n % (row[1], row[0]) logs += /home/%s/%s/log/error.log \n % (row[1], row[0

Re: Coding Help

2007-11-10 Thread Florian Lindner
Marc 'BlackJack' Rintsch wrote: On Sat, 10 Nov 2007 09:45:47 -0800, rishiyoor wrote: I need help coding my flowchart. The C's are conditions, the S's are statements. The statements do not affect the conditions except for S5 which is an increment for C0. The left is True, and the right is

Problem with format string / MySQL cursor

2007-10-18 Thread Florian Lindner
Hello, I have a string: INSERT INTO mailboxes (`name`, `login`, `home`, `maildir`, `uid`, `gid`, `password`) VALUES (%s, %s, %s, %s, %i, %i, %s) that is passed to a MySQL cursor from MySQLdb: ret = cursor.execute(sql, paras) paras is: ('flindner', '[EMAIL PROTECTED]', '/home/flindner/',

Re: Problem with format string / MySQL cursor

2007-10-18 Thread Florian Lindner
On 18 Okt., 22:08, Paul McNett [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: On Oct 19, 7:32 am, Florian Lindner [EMAIL PROTECTED] wrote: Hello, I have a string: INSERT INTO mailboxes (`name`, `login`, `home`, `maildir`, `uid`, `gid`, `password`) VALUES (%s, %s, %s, %s, %i, %i, %s

Re: Problem with MySQL cursor

2007-10-12 Thread Florian Lindner
Carsten Haese wrote: On Thu, 2007-10-11 at 15:14 +0200, Florian Lindner wrote: Hello, I have a function that executes a SQL statement with MySQLdb: def executeSQL(sql, *args): print sql % args cursor = conn.cursor() cursor.execute(sql, args) cursor.close() it's

Last iteration?

2007-10-12 Thread Florian Lindner
Hello, can I determine somehow if the iteration on a list of values is the last iteration? Example: for i in [1, 2, 3]: if last_iteration: print i*i else: print i that would print 1 2 9 Can this be acomplished somehow? Thanks, Florian --

Problem with global

2007-10-12 Thread Florian Lindner
Hello, I have a little problem with the global statement. def executeSQL(sql, *args): try: import pdb; pdb.set_trace() cursor = db.cursor() # db is type 'NoneType'. [...] except: print Problem contacting MySQL database. Please contact root.

Re: Problem with MySQL cursor

2007-10-12 Thread Florian Lindner
Carsten Haese wrote: On Fri, 2007-10-12 at 13:12 +0200, Florian Lindner wrote: Carsten Haese wrote: sql = INSERT INTO +DOMAIN_TABLE+(+DOMAIN_FIELD+) VALUES (%s) executeSQL(sql, domainname) Ok, I understand it and now it works, but why is limitation? Why can't I just the string

test if email

2007-10-12 Thread Florian Lindner
Hello, is there a function in the Python stdlib to test if a string is a valid email address? Thanks, florian -- http://mail.python.org/mailman/listinfo/python-list

Re: test if email

2007-10-12 Thread Florian Lindner
[EMAIL PROTECTED] wrote: On Oct 12, 2:55 pm, Florian Lindner [EMAIL PROTECTED] wrote: Hello, is there a function in the Python stdlib to test if a string is a valid email address? Thanks, florian What do you mean? If you're just testing the construction of the email address string

Re: Problem with global

2007-10-12 Thread Florian Lindner
Larry Bates wrote: Florian Lindner wrote: Hello, I have a little problem with the global statement. def executeSQL(sql, *args): try: import pdb; pdb.set_trace() cursor = db.cursor() # db is type 'NoneType'. [...] except: print Problem

Problem with MySQL cursor

2007-10-11 Thread Florian Lindner
Hello, I have a function that executes a SQL statement with MySQLdb: def executeSQL(sql, *args): print sql % args cursor = conn.cursor() cursor.execute(sql, args) cursor.close() it's called like that: sql = INSERT INTO %s (%s) VALUES (%s) executeSQL(sql, DOMAIN_TABLE,

Formal interfaces with Python

2007-05-28 Thread Florian Lindner
Hello, some time ago I've heard about proposals to introduce the concecpt of interfaces into Python. I found this old and rejected PEP about that: http://www.python.org/dev/peps/pep-0245/ What is the current status of that? Thanks, Florian -- http://mail.python.org/mailman/listinfo/python-list

Convert from/to struct_time

2007-04-22 Thread Florian Lindner
Hello, I have a struct_time and a datetime object and need compare them. Is there any function that converts either of these two to another? Thanks, Florian -- http://mail.python.org/mailman/listinfo/python-list

Re: RSS feed parser

2007-04-04 Thread Florian Lindner
[EMAIL PROTECTED] wrote: On Apr 2, 10:20 pm, Florian Lindner [EMAIL PROTECTED] wrote: Some of the question I have but found answered nowhere: I have a feedparser object that was created from a string. How can I trigger a update (from a new string) but the feedparser should treat the new

RSS feed parser

2007-04-02 Thread Florian Lindner
Hello, I'm looking for python RSS feed parser library. Feedparser http://feedparser.org/ does not seem to maintained anymore. What alternatives are recommendable? Thanks, Florian -- http://mail.python.org/mailman/listinfo/python-list

Re: RSS feed parser

2007-04-02 Thread Florian Lindner
[EMAIL PROTECTED] wrote: On Apr 2, 7:22 pm, Florian Lindner [EMAIL PROTECTED] wrote: Hello, I'm looking for python RSS feed parser library. Feedparserhttp://feedparser.org/does not seem to maintained anymore. What alternatives are recommendable? Thanks, Florian Well, even if it's

Using string as file

2007-03-05 Thread Florian Lindner
Hello, I have a function from a library thast expects a file object as argument. How can I manage to give the function a string resp. have the text it would have written to file object as a string? Thanks, Florian -- http://mail.python.org/mailman/listinfo/python-list

RSS feed creator

2007-03-04 Thread Florian Lindner
Hello, I'm looking for a python library that creates a RSS and/or Atom feed. E.g. I give a list like that: [ [title1, short desc1, author1], [title2, short desc2, author2], ] and the library creates a valid feed XML file. (return as a string) Thanks, Florian --

Static variables

2007-01-24 Thread Florian Lindner
Hello, does python have static variables? I mean function-local variables that keep their state between invocations of the function. Thanks, Florian -- http://mail.python.org/mailman/listinfo/python-list

Re: ConfigParser and multiple option names

2006-05-10 Thread Florian Lindner
[EMAIL PROTECTED] wrote: that will break horribly in windows, remenber it install all it's crap in c:\Program Files Why should this break? If you split at the \n character? Florian -- http://mail.python.org/mailman/listinfo/python-list

Calling superclass

2006-05-04 Thread Florian Lindner
Hello, I try to call the superclass of the ConfigParser object: class CustomizedConfParser(ConfigParser.SafeConfigParser): def get(self, section, attribute): try: return super(CustomizedConfParser, self).get(section, attribute) # [...] but that gives only

Gettings subdirectories

2006-05-03 Thread Florian Lindner
Hello, how can I get all subdirectories of a given directories? os.listdir() gives me all entries and I've found no way to tell if an object is a file or a directory. Thanks, Florian -- http://mail.python.org/mailman/listinfo/python-list

ConfigParser and multiple option names

2006-05-02 Thread Florian Lindner
Hello, since ConfigParser does not seem to support multiple times the same option name, like: dir=/home/florian dir=/home/john dir=/home/whoever (only the last one is read in) I wonder what the best way to work around this. I think the best solution would be to use a seperation character:

Re: ConfigParser and multiple option names

2006-05-02 Thread Florian Lindner
Alexis Roda wrote: Florian Lindner escribió: I think the best solution would be to use a seperation character: dir=/home/florian, /home/john, home/whoever RCS uses , in filenames A kommata (,) is a valid character in path names. Ok, you can use quotes. What do you think? Any better

RFC 822 continuations

2006-05-02 Thread Florian Lindner
Hello, http://docs.python.org/lib/module-ConfigParser.html writes: with continuations in the style of RFC 822; what is meant with these continuations? Thanks, Florian -- http://mail.python.org/mailman/listinfo/python-list

Get path of a class

2006-01-09 Thread Florian Lindner
Hello, how can I get the path of a class. I managed to do it with c.__module__ + . + c.__name__ but I'm sure there is a better way. Thanks, Florian -- http://mail.python.org/mailman/listinfo/python-list

Re: Graphical debugger/code explorer

2005-10-04 Thread Florian Lindner
benz wrote: PYTHON_IDE={ 'spe' : 'http://spe.pycs.net/', 'eric3' : 'http://www.die-offenbachs.de/detlev/eric3.html', 'drpython' : 'http://drpython.sourceforge.net/'} I've tried out eric3 and it looks promising. However, I have one problem. I open a file which is part of Zope and set a

Graphical debugger/code explorer

2005-10-03 Thread Florian Lindner
Hello, in order to understand python code from a larger project (Zope 3) I'm looking for a tool that helps me with that. It should also help What (graphical) application running on Linux can you recommend? Thanks, Florian -- http://mail.python.org/mailman/listinfo/python-list

Monitoring a directory for changes

2005-09-20 Thread Florian Lindner
Hello, is there a python lib (preferably in the std lib) to monitor a directory for changes (adding / deleting files) for Linux 2.6? Thanks, Florian -- http://mail.python.org/mailman/listinfo/python-list

Re: Python for Webscripting (like PHP)

2005-08-19 Thread Florian Lindner
Florian Lindner wrote: Hello, I've been using Python a lot for scripting (mainly scripts for server administration / DB access). All these scripts were shell based. Now I'm considering using Python (with mod_python on Apache 2) for a web project, just how I've used PHP in some smaller

Python for Webscripting (like PHP)

2005-08-18 Thread Florian Lindner
Hello, I've been using Python a lot for scripting (mainly scripts for server administration / DB access). All these scripts were shell based. Now I'm considering using Python (with mod_python on Apache 2) for a web project, just how I've used PHP in some smaller Projects before (?php print foo

directory traverser

2005-07-09 Thread Florian Lindner
Hello, IIRC there is a directory traverser for walking recursively through subdirectories in the standard library. But I can't remember the name and was unable to find in the docs. Anyone can point me to it? Thanks, Florian -- http://mail.python.org/mailman/listinfo/python-list

Problem with sha.new

2005-07-09 Thread Florian Lindner
Hello, I try to compute SHA hashes for different files: for root, dirs, files in os.walk(sys.argv[1]): for file in files: path = os.path.join(root, file) print path f = open(path) sha = sha.new(f.read()) sha.update(f.read()) print

Re: What are the other options against Zope?

2005-07-03 Thread Florian Lindner
Peter Hansen wrote: Florian Lindner wrote: Peter Hansen wrote: [Zope] doesn't include database interfaces other than to its own ZODB. That's not correct. Zope2 includes DB interfaces to MySQL, PostGre, ODBC and many others. It actually *includes* them? I thought those were all add

Re: What are the other options against Zope?

2005-07-02 Thread Florian Lindner
Peter Hansen wrote: godwin wrote: I wanna thank Martin for helping out with my ignorance concerning execution of stored procedure with python. Now i have decided to write a web app that googles into my companies proprietary database. Just checking... do you really mean googles, or is

key - key pairs

2005-06-23 Thread Florian Lindner
Hello, is there in python a kind of dictionary that supports key - key pairs? I need a dictionary in which I can access a certain element using two different keys, both unique. For example: I've a dictionary with strings and times. Sometimes I have the string and I want to have the time, other

timedelta comparision with gmtime()

2005-06-22 Thread Florian Lindner
Hello, I want to know if a certain duration is over. I try it like this with timedelta objects: d = datetime.timedelta(minutes = 2) t = time.gmtime() print (t + d time.gmtime()) gives: TypeError: unsupported operand type(s) for +: 'datetime.timedelta' and 'time.struct_time' How to do that

Optimize a cache

2005-06-22 Thread Florian Lindner
Hello, I am building a object cache in python, The cache has a maximum size and the items have expiration dates. At the moment I'm doing like that: cache = {} # create dictionary cache[ID] = (object, timestamp) # Save a tuple with the object itself and a timestamp (from datetime.datetime.now())

Escape spaces in strings

2005-05-12 Thread Florian Lindner
Hello, is there a function to escape spaces and other characters in string for using them as a argument to unix command? In this case rsync (http://samba.anu.edu.au/rsync/FAQ.html#10) Thx, Florian -- http://mail.python.org/mailman/listinfo/python-list

Problems with csv module

2005-05-11 Thread Florian Lindner
Hello, I've one problem using the csv module. The code: self.reader = csv.reader(f, delimiter = ,) works perfectly. But when I use a variable for delimiter: self.reader = csv.reader(f, delimiter = Adelimiter) I get the traceback: File

Re: Problems with csv module

2005-05-11 Thread Florian Lindner
Richie Hindle wrote: [Florian] I've one problem using the csv module. The code: self.reader = csv.reader(f, delimiter = ,) works perfectly. But when I use a variable for delimiter: self.reader = csv.reader(f, delimiter = Adelimiter) I get the traceback: File

Re: Problems with csv module

2005-05-11 Thread Florian Lindner
Richie Hindle wrote: [Florian] You mean that csv.reader can't work with unicode as the delimiter parameter? Exactly. http://www.python.org/doc/2.3.5/lib/module-csv.html says: Note: This version of the csv module doesn't support Unicode input. Also, there are currently some issues

bad argument type for built-in operation

2005-05-10 Thread Florian Lindner
Hello, I've the traceback: Traceback (most recent call last): File visualizer.py, line 8, in ? main() File visualizer.py, line 5, in main g = GraphCreator(f) File /home/florian/visualizer/GraphCreator.py, line 13, in __init__ self.conf = ConfigReader(config) File

Getting number of iteration

2005-05-06 Thread Florian Lindner
Hello, when I'm iterating through a list with: for x in list: how can I get the number of the current iteration? Thx, Florian -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem with pyXML DOM

2005-05-04 Thread Florian Lindner
Maniac wrote: Florian Lindner wrote: Traceback (most recent call last): File ConfigReader.py, line 40, in ? c = ConfigReader(f) File ConfigReader.py, line 32, in __init__ print sourceNode.getElementsByTagName(filename)[0].nodeValue() TypeError: 'NoneType' object is not callable

Problem with pyXML DOM

2005-05-04 Thread Florian Lindner
Hello, I'm using the PyXML Package. My XML document looks like that: visConf graph name=testgraph1 type=chart source type=CSV filename/home/florian/visualizer/testdata.csv/filename /source /graph /visConf print sourceNode.getElementsByTagName(filename)[0] print

Variable option count

2005-05-04 Thread Florian Lindner
Hello, how can I give an arbitrary number of options in a automated way to a function? Example. I've the list A = [ 1 2 3 ... ] Now I want to give this list to a function so that it is the same for function like: f(1, 2, 3, ...) How can I do that? Thanks,

Comparision of GUI framworks

2005-05-02 Thread Florian Lindner
Hello, I've read the chapter in the Python documentation, but I'm interested in a a more in-depth comparision. Especially regarding how pythonic it is and how well it performs and looks under Windows. I've some C++ experiences with Qt, so I'm very interested to have PyQt compared to wxWindows and

Libraries for creating graphs

2005-05-02 Thread Florian Lindner
Hello, I'm looking for libraries to create graphs. I'm not talking about plotting a function like f(x)=x^2 just plotting a couple of values into a short, maybe interpolating them. Output should be something like JPEG. Thx, Florian -- http://mail.python.org/mailman/listinfo/python-list

Re: Secure scripts variables

2005-03-30 Thread Florian Lindner
Paul Rubin wrote: Florian Lindner [EMAIL PROTECTED] writes: I have a script which is readable and executable by a user, but not writable. The users executes the scripts, it reads in a value and based on this value it computes a result and stores it in a variable. Can the user read out

Secure scripts variables

2005-03-29 Thread Florian Lindner
Hello, given the following situation: I have a script which is readable and executable by a user, but not writable. The users executes the scripts, it reads in a value and based on this value it computes a result and stores it in a variable. Can the user read out the value of this variable? If

Re: Save passwords in scripts

2005-03-28 Thread Florian Lindner
Serge Orlov wrote: Florian Lindner wrote: Paul Rubin wrote: - sort of similar: have a separate process running that knows the password (administrator enters it at startup time). That process listens on a unix socket and checks the ID of the client. It reveals the password to authorized

Save passwords in scripts

2005-03-21 Thread Florian Lindner
Hello, I've a scripts that allows limited manipulation of a database to users. This script of course needs to save a password for the database connection. The users, on the other hand need read permission on the script in order to execute it but should not be able to read out the password. What is

Re: Save passwords in scripts

2005-03-21 Thread Florian Lindner
Peter Hansen wrote: Florian Lindner wrote: I've a scripts that allows limited manipulation of a database to users. This script of course needs to save a password for the database connection. The users, on the other hand need read permission on the script in order to execute it but should

Re: Save passwords in scripts

2005-03-21 Thread Florian Lindner
Esben Pedersen wrote: Florian Lindner wrote: Hello, I've a scripts that allows limited manipulation of a database to users. This script of course needs to save a password for the database connection. The users, on the other hand need read permission on the script in order to execute

Re: Save passwords in scripts

2005-03-21 Thread Florian Lindner
Paul Rubin wrote: Florian Lindner [EMAIL PROTECTED] writes: I've a scripts that allows limited manipulation of a database to users. This script of course needs to save a password for the database connection. The users, on the other hand need read permission on the script in order to execute

Mark attribute as read-only

2005-03-16 Thread Florian Lindner
Hello, how can I mark a attribute of a class as read-only (for non classmembers)? Yes, stupid question, but the docu gave me no help. Thanks, Florian -- http://mail.python.org/mailman/listinfo/python-list

Lib for RSS/Atom parsing

2005-02-27 Thread Florian Lindner
Hello, what is a good python library for parsing of RSS and/or Atom feeds. It should be able to handle most of the common protocols. Thanks, Florian -- http://mail.python.org/mailman/listinfo/python-list

How to access database?

2005-01-03 Thread Florian Lindner
Hello, AFAIK python has a generic API for database access which adapters are supposed to implement. How can I found API documentation on the API? Thanks, Florian -- http://mail.python.org/mailman/listinfo/python-list

Forums based on python

2004-12-06 Thread Florian Lindner
Hello, which free forums, based on mod_python and MySQL are around there? Something like phpBB... Thanks, Florian -- http://mail.python.org/mailman/listinfo/python-list