matplotlib under Zope
i develop an application under zope with windows 2000 and i would like integrate graphs. the problem is that the installation of matplotlib doesn't find the python of zope and so i can't make graph. Maybe a problem of register? could you help me? thanks -- http://mail.python.org/mailman/listinfo/python-list
variables exist
how testing if a variable exists in python as isset in php?? thanks -- http://mail.python.org/mailman/listinfo/python-list
Fwd: Python-list Digest, Vol 106, Issue 1
(a2 + b2 = c2) = (e < | > P a P b P c) Beschreibt eine Disonanz in Genese. -- Weitergeleitete Nachricht -- Von: Datum: 30.06.2012 23:09 Betreff: Python-list Digest, Vol 106, Issue 1 An: Send Python-list mailing list submissions to python-list@python.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.python.org/mailman/listinfo/python-list or, via email, send a message with subject or body 'help' to python-list-requ...@python.org You can reach the person managing the list at python-list-ow...@python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Python-list digest..." Today's Topics: 1. Re: code review (Alister) 2. Re: code review (Alister) 3. Re: code review (Thomas Jollans) 4. Re: code review (Alain Ketterlin) 5. Re: code review (Thomas Jollans) 6. Re: tiffany 0.6.1 released (Christian Heimes) 7. Re: code review (Terry Reedy) 8. Re: code review (Martin P. Hellwig) 9. Re: code review (Thomas Jollans) 10. Re: code review (Alain Ketterlin) -- Weitergeleitete Nachricht -- From: Alister To: python-list@python.org Cc: Date: Sat, 30 Jun 2012 20:25:39 GMT Subject: Re: code review On Sat, 30 Jun 2012 12:29:31 +0200, Peter Otten wrote: > Alister wrote: > >> I think I may be on firmer grounds with the next few: >> >> isValidPassword can be simplified to >> >> def isValidPassword(password: >> count=len(password) >> return count>= mud.minpass and count<= mud.maxpass >> >> ( I used count to save finding the length of password twice although it >> probably makes no difference in this scenario) > > If you spell it > > def is_valid_password(password): > return mud.minpass <= len(password) <= mud.maxpass > > it is even easier to see that you are performing an interval check. I realise that was possible, that is brilliant! it is exactly how you would write it ass a mathematical definition. -- "The only real way to look younger is not to be born so soon." -- Charles Schulz, "Things I've Had to Learn Over and Over and Over" -- Weitergeleitete Nachricht -- From: Alister To: python-list@python.org Cc: Date: Sat, 30 Jun 2012 20:30:45 GMT Subject: Re: code review On Sat, 30 Jun 2012 21:38:58 +0200, Thomas Jollans wrote: > On 06/30/2012 08:39 PM, Thomas 'PointedEars' Lahn wrote: >> Peter Otten wrote: >> >>> If you spell it >>> >>> def is_valid_password(password): >>> return mud.minpass <= len(password) <= mud.maxpass >>> >>> it is even easier to see that you are performing an interval check. >> >> This is probably a tautology around here, but *what* *a* *great* >> *programming* *language*. >> >> > Personally, I don't like this feature of the language. I find a ternary > operator that uses symbols that can also be binary operators confusing > and inconsistent with the way operators usually work/the way terms are > usually associated. > > It has the charm of being something you'd "naturally" write in the > context of non-programming mathematics, at the cost of being very odd > indeed in the context of programming in general and Python in > particular. Surely this fits perfectly with the lines 1 & 7 in the zen of python (import this) "Beautifull is better than ugly" and "Readability counts" I find that construct both beautiful and readable, if it cannot be used in the languages then that is their loss. -- Removing the straw that broke the camel's back does not necessarily allow the camel to walk again. -- Weitergeleitete Nachricht -- From: Thomas Jollans To: python-list@python.org Cc: Date: Sat, 30 Jun 2012 22:50:43 +0200 Subject: Re: code review On 06/30/2012 10:30 PM, Alister wrote: > On Sat, 30 Jun 2012 21:38:58 +0200, Thomas Jollans wrote: > >> On 06/30/2012 08:39 PM, Thomas 'PointedEars' Lahn wrote: >>> Peter Otten wrote: >>> If you spell it def is_valid_password(password): return mud.minpass <= len(password) <= mud.maxpass it is even easier to see that you are performing an interval check. >>> >>> This is probably a tautology around here, but *what* *a* *great* >>> *programming* *language*. >>> >>> >> Personally, I don't like this feature of the language. I find a ternary >> operator that uses symbols that can also be binary operators confusing >> and inconsistent with the way operators usually work/the way terms are >> usually associated. >> >> It has the charm of being something you'd "naturally" write in the >> context of non-programming mathematics, at the cost of being very odd >> indeed in the context of programming in general and Python in >> particular. > > Surely this fits perfectly with the lines 1 & 7 in the zen of python > (import this) > "Beautifull is better than ugly" and "Readability counts" > > I find that construct both beautiful and readable, if it cannot be used > in the languages then that is
Re: Problem when scraping the 100 Movie titles.
#Try using, it's save in json format of the website: import json import requests from bs4 import BeautifulSoup url = "https://www.empireonline.com/movies/features/best-movies-2/"; soup = BeautifulSoup(requests.get(url).content, "html.parser") data = json.loads(soup.select_one("#__NEXT_DATA__").contents[0]) # uncomment this to print all data: #print(json.dumps(data, indent=4)) def find_articles(data): if isinstance(data, dict): for k, v in data.items(): if k.startswith("ImageMeta:"): yield v['image']['name'] else: yield from find_articles(v) elif isinstance(data, list): for i in data: yield from find_articles(i) for a in find_articles(data): print(a) -- https://mail.python.org/mailman/listinfo/python-list
Re: How to test for type or instance of dict_values?
Very late to the party, but I just encountered a very similar problem and found a solution: ``` import collections obj = {"foo": "bar"} isinstance(obj.values(), collections.abc.ValuesView) # => True ``` Hope that helps someone out there :) On Thursday, November 17, 2016 at 9:09:23 AM UTC-8, Terry Reedy wrote: > On 11/17/2016 9:57 AM, Thorsten Kampe wrote: > > > The code in question is part of an attempt to get the dimensions of > > multi-dimensional lists, the `isinstance` is there in order to > > exclude strings. > > You can do the exclusion directly. > > > > > """ > > def dim(seq): > > dimension = [] > > while isinstance(seq, (list, tuple)): > > while not isinstance(seq, str) # or (str, bytes, ...) > > > dimension.append(len(seq)) > > try: > > seq = seq[0] > > except IndexError: # sequence is empty > > break > > return dimension > > """ > > > > Thorsten > > > > > -- > Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
COM error Access is denied
Hello, I try to make web testing using Pamie and it use win32com to call Internet Explorer. A access denied COM_error occurs and I don't know how to solve it. I'm administrator of my workstation and I install myself Pyton and win32com Any idea ? File "D:\pyatf\Browser.py", line 32, in do exec "self.%s(*args)" % actionName File "", line 1, in ? File "C:\Python24\lib\site-packages\cPAMIE.py", line 1024, links[linkNum].Click() File "C:\Python24\Lib\site-packages\win32com\client\dynamic __call__ return self._get_good_object_(self._oleobj_.Invoke(*allAr defaultDispatchName,None) com_error: (-2147024891, 'Access is denied.', None, None) --- Thanks Fabian Skivée -- http://mail.python.org/mailman/listinfo/python-list
extending class static members and inheritance
Hi All, I have a question. Let says I have the following two classes: class Base(object): __mylist__ = ["value1", "value2"] def somemethod(self): pass class Derived(Base): __mylist__ = ["value3", "value4"] def anothermethod(self): pass what I would like to accomplish is that the class Derived has the member __mylist__ extended or merged as ["value1", "value2", "value3", "value4"]. Is there anyway I could accomplish this? I was thinking on accomplishing this as follows: class Derived(Base): __mylist__ = Base.__mylist__ + ["value3", "value4"] def anothermethod(self): pass Is there a better way? Perhaps a decorator? Thanks in advance and regards, Fabian -- http://mail.python.org/mailman/listinfo/python-list
Different cache filename
Hi, when load a module "mymodule.py" with importlib.machinery.SourceFileLoader a bytecode file is created as mymodule.cpython-33.pyc. If I load a module "mymodule.ext.py" the same way the same bytecode file is created as mymodule.cpython-33.pyc. Is there any way I could tell python to generate the bycode file as mymodule.ext.cpython-33.pyc? Regards, Fabian -- http://mail.python.org/mailman/listinfo/python-list
getsockopt
Hello, my name is fabian and i'm a student from northern germany. right now i try to create som kind of decapsulation of esp-udp packets using python. therefor i need to use the socket.getsockopt (SOL_IP, IP_OPTIONS, 20) method. But al i get is some empty value. Nothin. Does someone know or have an working exmaple of how to use this method?? The lines: s = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP) s.bind(('',4500)) while 1:# Run until cancelled message, client = s.recvfrom(1400) # <=256 byte datagram hdr = s.getsockopt (SOL_IP, IP_OPTIONS, 20) print "Client connected:", client print "HDR:" + binascii.hexlify(hdr) greetings and ta - fabiand -- http://mail.python.org/mailman/listinfo/python-list
Re: getsockopt
Forgot: > The lines: > s = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP) > s.bind(('',4500)) > while 1:# Run until cancelled > message, client = s.recvfrom(1400) # <=256 byte datagram > hdr = s.getsockopt (SOL_IP, IP_OPTIONS, 20) > print "Client connected:", client > print "HDR:" + binascii.hexlify(hdr) > If you want to test this, be rot and try echo asd | nc -u 127.0.0.1 4500 to create some packets ... This should do it. - fabiand -- http://mail.python.org/mailman/listinfo/python-list
Re: getsockopt
> --- Ursprüngliche Nachricht --- > Von: Steve Holden <[EMAIL PROTECTED]> > An: python-list@python.org > Betreff: Re: getsockopt > Datum: Fri, 16 Dec 2005 08:29:08 + > > Fabian Deutsch wrote: > > Hello, > > > > my name is fabian and i'm a student from northern germany. right now i > > try to create som kind of decapsulation of esp-udp packets using python. > > > > therefor i need to use the socket.getsockopt (SOL_IP, IP_OPTIONS, 20) > > method. But al i get is some empty value. Nothin. > > > > Does someone know or have an working exmaple of how to use this method?? > > > > The lines: > > s = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP) > > s.bind(('',4500)) > > while 1:# Run until cancelled > > message, client = s.recvfrom(1400) # <=256 byte datagram > > hdr = s.getsockopt (SOL_IP, IP_OPTIONS, 20) > > print "Client connected:", client > > print "HDR:" + binascii.hexlify(hdr) > > > Perhaps you're getting an empty string back because no IP options are > set in the received packets' headers? > Hey, you are right - i just re-read the ip (7) man - i only get the ip options .. but do you know a way of getting the whole header? 'cause what i'm trying to do is, to "remove" the udp-header of the packet i recieved and sendind a new packet without the udp-header. I want to do this by taking it's payload (incl. esp-hdr) and ip-header and resending it to my system creating a new packet with the old ip-header and payload (incl. esp-hdr) i got from the recvd packet. Before: ++-+--+--- - - | IP HDR | UDP HDR | ESP HDR | PAYLOAD ... ++-+--+--- - - After : ++-+--- - - | IP HDR | ESP HDR | PAYLOAD ... ++-+--- - - regards fabian -- Fabian Deutsch <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list
Re: getsockopt
Stave Holde wrote: > Fabian Deutsch wrote: > >>--- Ursprüngliche Nachricht --- > >>Von: Steve Holden <[EMAIL PROTECTED]> > >>An: python-list@python.org > >>Betreff: Re: getsockopt > >>Datum: Fri, 16 Dec 2005 08:29:08 + > >> > >>Fabian Deutsch wrote: > >> > >>>Hello, > >>> > >>>my name is fabian and i'm a student from northern germany. right now i > >>>try to create som kind of decapsulation of esp-udp packets using > python. > >>> > >>>therefor i need to use the socket.getsockopt (SOL_IP, IP_OPTIONS, 20) > >>>method. But al i get is some empty value. Nothin. > >>> > >>>Does someone know or have an working exmaple of how to use this > method?? > >>> > >>>The lines: > >>>s = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP) > >>>s.bind(('',4500)) > >>>while 1:# Run until cancelled > >>> message, client = s.recvfrom(1400) # <=256 byte datagram > >>>hdr = s.getsockopt (SOL_IP, IP_OPTIONS, 20) > >>>print "Client connected:", client > >>>print "HDR:" + binascii.hexlify(hdr) > >>> > >> > >>Perhaps you're getting an empty string back because no IP options are > >>set in the received packets' headers? > >> > > > > Hey, > > you are right - i just re-read the ip (7) man - i only get the ip > options .. > > > > but do you know a way of getting the whole header? > > > > 'cause what i'm trying to do is, to "remove" the udp-header of the > packet i > > recieved and sendind a new packet without the udp-header. > > I want to do this by taking it's payload (incl. esp-hdr) and ip-header > and > > resending it to my system creating a new packet with the old ip-header > and > > payload (incl. esp-hdr) i got from the recvd packet. > > > > Before: > > ++-+--+--- - - > > | IP HDR | UDP HDR | ESP HDR | PAYLOAD ... > > ++-+--+--- - - > > After : > > ++-+--- - - > > | IP HDR | ESP HDR | PAYLOAD ... > > ++-+--- - - > > > I'm not sure where ESP is going to come into this, or how the traffic > you will be receiving will be generated. I suspect you may need to > reconsider your application design a little. > > The only way to get hold of the IP headers is to use SOCK_RAW, which > delivers everything that comes in from the packet driver. > > What is it you're actually trying to do? If you perform the > transformation you outline in the diagrams above then the IP header will > certainly contain the wrong protocol value for a start. > Well actually I managed to recieve the encapsulated esp packages, decapsulate them and send them to my system using sr = socket(AF_INET, SOCK_RAW, IPPROTO_ESP) ... sr.sendto(message (MY_IP,0)) it does work and my system correctly deciphers the packages (i get an icmo oing request and my system answers with icmp reply) but the problem is, that the src_adr of the esp_package is set to my local adr and not the adr of the original esp-udp_packet sender ... so i try to use sr.send to send the message, but then i will have to create the whole header ... but i dont't want to create it but copy it from the recived packet to the new one .. i hope you understand what i am trying to say .. fabian -- Fabian Deutsch <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list
Re: Re: getsockopt
Steve Holden wrote: > Fabian Deutsch wrote: > >>--- Ursprüngliche Nachricht --- > >>Von: Steve Holden <[EMAIL PROTECTED]> > >>An: python-list@python.org > >>Betreff: Re: getsockopt > >>Datum: Fri, 16 Dec 2005 08:29:08 + > >> > >>Fabian Deutsch wrote: > >> > >>>Hello, > >>> > >>>my name is fabian and i'm a student from northern germany. right now i > >>>try to create som kind of decapsulation of esp-udp packets using > python. > >>> > >>>therefor i need to use the socket.getsockopt (SOL_IP, IP_OPTIONS, 20) > >>>method. But al i get is some empty value. Nothin. > >>> > >>>Does someone know or have an working exmaple of how to use this > method?? > >>> > >>>The lines: > >>>s = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP) > >>>s.bind(('',4500)) > >>>while 1:# Run until cancelled > >>> message, client = s.recvfrom(1400) # <=256 byte datagram > >>>hdr = s.getsockopt (SOL_IP, IP_OPTIONS, 20) > >>>print "Client connected:", client > >>>print "HDR:" + binascii.hexlify(hdr) > >>> > >> > >>Perhaps you're getting an empty string back because no IP options are > >>set in the received packets' headers? > >> > > > > Hey, > > you are right - i just re-read the ip (7) man - i only get the ip > options .. > > > > but do you know a way of getting the whole header? > > > > 'cause what i'm trying to do is, to "remove" the udp-header of the > packet i > > recieved and sendind a new packet without the udp-header. > > I want to do this by taking it's payload (incl. esp-hdr) and ip-header > and > > resending it to my system creating a new packet with the old ip-header > and > > payload (incl. esp-hdr) i got from the recvd packet. > > > > Before: > > ++-+--+--- - - > > | IP HDR | UDP HDR | ESP HDR | PAYLOAD ... > > ++-+--+--- - - > > After : > > ++-+--- - - > > | IP HDR | ESP HDR | PAYLOAD ... > > ++-+--- - - > > > I'm not sure where ESP is going to come into this, or how the traffic > you will be receiving will be generated. I suspect you may need to > reconsider your application design a little. > > The only way to get hold of the IP headers is to use SOCK_RAW, which > delivers everything that comes in from the packet driver. > > What is it you're actually trying to do? If you perform the > transformation you outline in the diagrams above then the IP header will > certainly contain the wrong protocol value for a start. You just need the ipsec tools to generate the traffic i want to decapsulate. setkey -c < Hinter dem Gartel 26a D-27711 Osterholz-Scharmbeck -- http://mail.python.org/mailman/listinfo/python-list
Starting a GUI application out of an console application
Hello! I am currently working on an alternative for the gnome-volume-manager for multiseat systems based on HAL and DBus. Whenever the signal 'DeviceAdded' is received I would like to start a GUI-Interface where the user can choose from different options. But now I am wondering how I should start this interface since this GUI must be started by a console daemon. What is the most common way to do that? Usually, I start a PyQt application that way: app = QApplication(sys.argv) ui = Dialog() app.setMainWidget(ui) ui.show() app.exec_loop() If I start it that way, I am not quite sure whether this will work since I have got two main loops then (the one of console daemon [implemented by using gobject.MainLoop().run()] and the Qt one). Moreover, once the Qt application is started, it should run independently of the console daemon. Unfortunately, I can't think of any possibility to achieve this aim. Do you have any suggestions? -- http://mail.python.org/mailman/listinfo/python-list
Recursive function returning a list
Hello! I have got a Python "Device" Object which has got a attribute (list) called children which my contain several other "Device" objects. I implemented it this way in order to achieve a kind of parent/child relationship. Now I would like to get all children of a given "Device" object and thought that it would be the best way to use recursive function. This is what I got so far: def getAllChildren(self, children=[]): if self.children: children.extend(self.children) for child in self.children: child.getAllChildren(children) return children Unfortunately, it doesn't work like expected since the default parameter children=[] is evaluated only once. That's why the children list becomes larger and larger after calling the method several times but I can't think of another possibility. Do you have any ideas? -- http://mail.python.org/mailman/listinfo/python-list
install python on cdrom
Hi, I look for an easy way to use the newest scipy, pyvtk, matplotlib, f2py, numpy, paraview/vtk,... on a entreprise redhat machine without administration rights. My first thought was to install the whole new python system on a cdrom/dvd and mounting it, when I need it. Would that be the easiest way? I would be glad to read some hints about the way doing it... Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: install python on cdrom
Hi Martin, * Martin v. Löwis <[EMAIL PROTECTED]> wrote: > Fabian Braennstroem schrieb: >> I look for an easy way to use the newest scipy, pyvtk, matplotlib, >> f2py, numpy, paraview/vtk,... on a entreprise redhat machine >> without administration rights. >> My first thought was to install the whole new python system >> on a cdrom/dvd and mounting it, when I need it. Would that >> be the easiest way? I would be glad to read some >> hints about the way doing it... > > If you have a home directory with sufficient disk space, the > easiest way would be to install Python into your home directory, > assuming administrative policy allows such usage of the > home directory. Thanks, but unfortunately the administrative policy does not allow such installation, but could it work, when I do such a installation in my home directory, copy everything to a cdrom/dvd and mount it in proper place? Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
email client like mutt
Hi, I am looking for a python email client for the terminal... something like mutt; maybe, so powerfull ;-) Would be nice, if anybody has an idea! Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
access abook addressbook with curses
Hi, I want to get access to my abook address file with python. Does anyone have some python lines to achive this using curses? If not, maybe anybody has small python program doing it with a gui!? Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: access abook addressbook with curses
Hi Ben, * Ben C <[EMAIL PROTECTED]> wrote: > On 2006-08-05, Fabian Braennstroem <[EMAIL PROTECTED]> wrote: >> Hi, >> >> I want to get access to my abook address file with python. >> Does anyone have some python lines to achive this using >> curses? If not, maybe anybody has small python program doing >> it with a gui!? > > You can just parse the abook addressbook with the ConfigParser, try > this: > > import os > from ConfigParser import * > > abook = ConfigParser() > abook.read(os.environ["HOME"] + "/.abook/addressbook") > > for s in abook.sections(): > print abook.items(s) Thanks! I found a different example too: import ConfigParser import string config = ConfigParser.ConfigParser() config.read("/home/fab/.abook/addressbook") # print summary print for number in [2,200]: print string.upper(config.get(str(number), "email")) print string.upper(config.get(str(number), "name")) print string.upper(config.get(str(number), "city")) print string.upper(config.get(str(number), "address")) but the problem seems to be that abook does not write every field, so I get an exception when there is a field missing: Traceback (most recent call last): File "configparser-example-1.py", line 13, in ? print string.upper(config.get(str(number), "city")) File "/usr/lib/python2.4/ConfigParser.py", line 520, in get raise NoOptionError(option, section) ConfigParser.NoOptionError: No option 'city' in section: '2' Section 2 looks like: [2] name=Andrs Gzi [EMAIL PROTECTED] nick=oz Is there a workaround? Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: email client like mutt
Hi to both, * cga2000 <[EMAIL PROTECTED]> wrote: > On Mon, Aug 07, 2006 at 08:34:16PM EDT, Aahz wrote: >> In article <[EMAIL PROTECTED]>, >> cga2000 <[EMAIL PROTECTED]> wrote: >> >On Sun, Aug 06, 2006 at 04:15:08PM EDT, Aahz wrote: >> >> In article <[EMAIL PROTECTED]>, >> >> Fabian Braennstroem <[EMAIL PROTECTED]> wrote: >> >>> >> >>>I am looking for a python email client for the terminal... something like >> >>>mutt; maybe, so powerfull ;-) >> >> >> >> What's wrong with mutt? >> > >> >Like he says it's not written in python. >> >> Yes, I see that, but that doesn't answer my question. Not every >> application in the world needs to be written in Python. (Note that I'm >> a mutt user myself.) > > Well.. I'm also curious why he wants it to be written in python, so I > thought we could join forces. > > Incidentally I've been looking for a general-purpose application written > in python/ncurses for some time and haven't found anything. > > Looks like no new terminal application was written in the last ten years > or so. I guess that would rule out python..? I like mutt a lot, but at work I have to use lotus notes and I thought that I could use an existing python mail client to read and write mail 'around ' the lotus environment... that probably does not work anyways!? The second idea, which is more a working together with mutt, was to send files from 'lfm' (last file manager), which is completely written in python. I want to open mutt from lfm and automatically attach the marked files to the email... Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: access abook addressbook with curses
Hi Ben, * Ben C <[EMAIL PROTECTED]> wrote: > On 2006-08-06, Fabian Braennstroem <[EMAIL PROTECTED]> wrote: >> Hi Ben, >> >> * Ben C <[EMAIL PROTECTED]> wrote: >>> On 2006-08-05, Fabian Braennstroem <[EMAIL PROTECTED]> wrote: >>>> Hi, >>>> >>>> I want to get access to my abook address file with python. >>>> Does anyone have some python lines to achive this using >>>> curses? If not, maybe anybody has small python program doing >>>> it with a gui!? >>> >>> You can just parse the abook addressbook with the ConfigParser, try >>> this: >>> >>> import os >>> from ConfigParser import * >>> >>> abook = ConfigParser() >>> abook.read(os.environ["HOME"] + "/.abook/addressbook") >>> >>> for s in abook.sections(): >>> print abook.items(s) >> >> Thanks! I found a different example too: >> >> import ConfigParser >> import string >> >> config = ConfigParser.ConfigParser() >> >> config.read("/home/fab/.abook/addressbook") >> >> # print summary >> print >> for number in [2,200]: >> print string.upper(config.get(str(number), "email")) >> print string.upper(config.get(str(number), "name")) >> print string.upper(config.get(str(number), "city")) >> print string.upper(config.get(str(number), "address")) >> >> but the problem seems to be that abook does not write every >> field, so I get an exception when there is a field missing: >> >> Traceback (most recent call last): >> File "configparser-example-1.py", line 13, in ? >> print string.upper(config.get(str(number), "city")) >> File "/usr/lib/python2.4/ConfigParser.py", line 520, in get >> raise NoOptionError(option, section) >> ConfigParser.NoOptionError: No option 'city' in section: '2' >> >> Section 2 looks like: >> >> [2] >> name=Andrs Gzi >> [EMAIL PROTECTED] >> nick=oz >> >> Is there a workaround? > > You can construct the parser with a dictionary of defaults: > > config = ConfigParser.ConfigParser({"city" : "unknown", > "zip" : "unknown"}) > > that kind of thing. > > Or catch the exceptions. Or use config.options("2") to see what options > exist in section 2 before you try to read them. Thanks! I will try it out! Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: access abook addressbook with curses
Hi Ben, * Ben C <[EMAIL PROTECTED]> wrote: > On 2006-08-08, Fabian Braennstroem <[EMAIL PROTECTED]> wrote: >> Hi Ben, >> >> * Ben C <[EMAIL PROTECTED]> wrote: >>> On 2006-08-06, Fabian Braennstroem <[EMAIL PROTECTED]> wrote: >>>> Hi Ben, >>>> >>>> * Ben C <[EMAIL PROTECTED]> wrote: >>>>> On 2006-08-05, Fabian Braennstroem <[EMAIL PROTECTED]> wrote: >>>>>> Hi, >>>>>> >>>>>> I want to get access to my abook address file with python. >>>>>> Does anyone have some python lines to achive this using >>>>>> curses? If not, maybe anybody has small python program doing >>>>>> it with a gui!? >>>>> >>>>> You can just parse the abook addressbook with the ConfigParser, try >>>>> this: >>>>> >>>>> import os >>>>> from ConfigParser import * >>>>> >>>>> abook = ConfigParser() >>>>> abook.read(os.environ["HOME"] + "/.abook/addressbook") >>>>> >>>>> for s in abook.sections(): >>>>> print abook.items(s) >>>> >>>> Thanks! I found a different example too: >>>> >>>> import ConfigParser >>>> import string >>>> >>>> config = ConfigParser.ConfigParser() >>>> >>>> config.read("/home/fab/.abook/addressbook") >>>> >>>> # print summary >>>> print >>>> for number in [2,200]: >>>> print string.upper(config.get(str(number), "email")) >>>> print string.upper(config.get(str(number), "name")) >>>> print string.upper(config.get(str(number), "city")) >>>> print string.upper(config.get(str(number), "address")) >>>> >>>> but the problem seems to be that abook does not write every >>>> field, so I get an exception when there is a field missing: >>>> >>>> Traceback (most recent call last): >>>> File "configparser-example-1.py", line 13, in ? >>>> print string.upper(config.get(str(number), "city")) >>>> File "/usr/lib/python2.4/ConfigParser.py", line 520, in get >>>> raise NoOptionError(option, section) >>>> ConfigParser.NoOptionError: No option 'city' in section: '2' >>>> >>>> Section 2 looks like: >>>> >>>> [2] >>>> name=Andrs Gzi >>>> [EMAIL PROTECTED] >>>> nick=oz >>>> >>>> Is there a workaround? >>> >>> You can construct the parser with a dictionary of defaults: >>> >>> config = ConfigParser.ConfigParser({"city" : "unknown", >>> "zip" : "unknown"}) >>> >>> that kind of thing. >>> >>> Or catch the exceptions. Or use config.options("2") to see what options >>> exist in section 2 before you try to read them. >> >> Thanks! I will try it out! > > Looking at the bigger picture here, though, I may be giving you the > wrong advice. Mutt just invokes abook to get the addresses I think, > that's why you put > > set query_command="abook --mutt-query '%s'" > > So you could do the same (if what you're trying to do is write a mutt > clone in Python): > > import subprocess > > name = "Andrs" > subprocess.Popen("abook --mutt-query " + name, > stdout=subprocess.PIPE, shell=True).communicate()[0] > > The difference is that this "leverages" abook to do the search, not just > to store the data, which is a logical approach. > > On the other hand, this way, you require that abook is installed on the > machine, which is no good if the object of the exercise is a portable > Python-only solution. The biggest problem is a missing and not allowed abook installation. But thanks for your tips! Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
radio buttons in curses
Hi, I want to add some radio and check buttons to my curses script. As I understand it, there are no buttons in the 'basic' curses module. Now, I found the curses-extra module, but I not able to download and install it. Does anybody have an idea, where I can download the module or, even better, how I can create radio and check buttons with the 'ordinary' curses module? Would be nice... Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: radio buttons in curses
Sorry, me again... Does nobody have an idea or is it to stupid? * Fabian Braennstroem <[EMAIL PROTECTED]> wrote: > Hi, > > I want to add some radio and check buttons to my curses > script. As I understand it, there are no buttons in the > 'basic' curses module. Now, I found the curses-extra module, > but I not able to download and install it. > > Does anybody have an idea, where I can download the module > or, even better, how I can create radio and check buttons > with the 'ordinary' curses module? Would be nice... > > Greetings! > Fabian > > -- > http://mail.python.org/mailman/listinfo/python-list > Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
extract certain values from file with re
== OUTER LOOP ITERATION = 416 CPU SECONDS = 2.28E+04 -- | Equation | Rate | RMS Res | Max Res | Linear Solution | +--+--+-+-+--+ | U-Mom| 0.96 | 1.8E-04 | 5.8E-03 | 1.8E-02 OK| | V-Mom| 0.98 | 3.6E-05 | 1.5E-03 | 4.4E-02 OK| | W-Mom| 0.99 | 4.5E-05 | 2.1E-03 | 4.3E-02 OK| | P-Mass | 0.96 | 8.3E-06 | 3.0E-04 | 12.9 4.0E-02 OK| +--+--+-+-+--+ | K-TurbKE | 0.98 | 1.5E-03 | 3.0E-02 | 5.7 2.5E-06 OK| | E-Diss.K | 0.97 | 4.2E-04 | 1.1E-02 | 12.3 3.9E-08 OK| +--+--+-+-+--+ With my sed/awk/grep/gnuplot script I would extract the values in the 'U-Mom' row using grep and print a certain column (e.g. 'Max Res') to a file and print it with gnuplot. Maybe I have to remove those '|' using sed before... Do you have an idea, how I can do this completely using python? Thanks for your help! Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: extract certain values from file with re
Hi to all, thanks a lot! I am pretty sure your ideas help :-) Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: Scientific computing and data visualization.
Hi, * Carl Friedrich Bolz <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: >> A commonly used data analysis framework is root (http://root.cern.ch). >> It offers a object oriented C++ framework with all kind of things one >> needs for plotting and data visualization. It comes along with PyRoot, >> an interface making the root objects available to Python. >> Take a look at the root manual for examples, it also contains a section >> describing the use of PyRoot. > > I can definitively second that. ROOT is a bit hard to learn but very, > very powerful and PyRoot is really a pleasure to work with. It sounds interesting. Right now, I use matplotlib for 2D plotting and vtk for 3D. Do you have any experience and can give some recommendations? Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: Scientific computing and data visualization.
Hi Bernhard, * [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >> > I can definitively second that. ROOT is a bit hard to learn but very, >> > very powerful and PyRoot is really a pleasure to work with. >> >> It sounds interesting. Right now, I use matplotlib for >> 2D plotting and vtk for 3D. Do you have any experience and >> can give some recommendations? > > Hi Fabian! > > I recommend using matplotlib for data visualization, because the usage > of the plotting commands is much(!!!) more convenient. In ROOT you have > to create objects before you can draw your diagrams. The constructor > often requires arguments about the number of space points, axis length, > name etc. On the other hand, the figure itself has a GUI to manipulate > the plot, which sometimes is nicer than doing everything in the script. > In particular the 3D visualization seems to be more comprehensive (lots > of drawing options, rotation of the plot with the mouse, changing of > visualization lego, surf, contour plots etc.). > > ROOT has more than plotting. For example it has a whole bunch of > containers to store very large amounts of data (within complex > datastructures), fitting routines, minimizers etc. But you get that > with scipy and numpy. > > I'm using 80% of the time matplotlib because it's much quicker for > quick glances at your data. If I need sophisitcated 3D plots, I use > ROOT, but I would love to switch to matplotlib for this, as well. > > My guess is that using python and matplotlib with scipy speeds up my > work by at least 30% in comparison to using purely ROOT (and code in > C++). And even 10-15% in comparison to the usage of ROOT with pyRoot. Thanks for your advice! Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
change directory when closing curses program
Hi, I am using lfm, a curses based file manager, and want to change into the last directory of my lfm-session after closing it. To be more clear: 1) run lfm from console in the home directory ~ 2) move to ~/something 3) close lfm 4) be in ~/something on the console Is that possible in any way? lfm uses a bash-function for this purpose , which does not work in tcsh ... :-( Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: Adding Worksheets to an Excel Workbook
Hi, just a small OT question coming from a linux openoffice system... * wesley chun <[EMAIL PROTECTED]> wrote: >> From: [EMAIL PROTECTED] >> Date: Tues, Oct 10 2006 2:08 pm >> >> I'm a Python newbie, and I'm just getting to the wonders of COM >> programming. > > > welcome to Python!! i too, have (recently) been interested in COM > programming, so much so that i added some material on Microsoft Office > (Win32 COM Client) Programming to the 2nd ed of my book, "Core Python > Programming" (see link below). it's only introductory material, but i > think you may find it useful as i have, and shows you how to create > simple applications for Excel, Word, PowerPoint, and Outlook. > > in addition to greg's code snippet, here's a snippet based on one from > the book (the code is under a CC license) -- it doesn't add a new > sheet, but does let you grab the "active" one (the one that is tabbed > and facing the user): > > # based on excel.pyw in Core Python Programming, 2nd ed > > from time import sleep > import win32com.client as win32 > > def excel(): > xl = win32.gencache.EnsureDispatch('Excel.Application') > ss = xl.Workbooks.Add() # add a new spreadsheet/workbook > sh = ss.ActiveSheet # grab the active sheet of the workbook > xl.Visible = True# make Excel show up on the desktop > sleep(1) > > sh.Cells(1,1).Value = 'Python-to-Excel Demo' > sleep(1) > for i in range(3, 8): > sh.Cells(i,1).Value = 'Line %d' % i > sleep(1) > sh.Cells(i+2,1).Value = "Th-th-th-that's all folks!" > > sleep(5) > ss.Close(False) # close the workbook and don't save > xl.Application.Quit() # quit Excel > > if __name__=='__main__': > excel() > > hope this helps! Does there exist something similar for powerpoint? Would be nice, if anybody can direct me to more examples... Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: 3D Vector Type Line-Drawing Program
Hi, I am not sure, if that is, what your looking for, but with 'salome' you able to produce 3D drawings with an GUI or using a python script. Take a look at: http://www.salome-platform.org/home/presentation/geom/ * Scott David Daniels <[EMAIL PROTECTED]> wrote: > Ron Adam wrote: >> Scott David Daniels wrote: >>> Ron Adam wrote: >>>> ... Is there a way to have the display show a wire frame image instead of >>>> shaded shapes? >>> You can draw the edges as lines. >> >> Is there a setting for this?, or are you suggesting reading the >> coordinates and creating curve objects for the edges? > Nope, you'd have to make a poly line which was the wire frame, but it > would then rotate and such with the rest of the model. Essentially > you would, for each primitive, have a wire-frame and a volumetric > version, and keep one of the two visible (with the other invisible) > at all times. > >>>> Is there an easy way to convert a display to something that can be >>>> printed? >>> >>> You can generate POV-ray source. This is not a system for creating >>> beautiful pictures, but rather a great 3-D sketch pad. > > Now POV-ray _will_ create beautiful pictures, but the texturing, > shading, and lighting control that POV-ray gives you exceeds that > of VPython. You could use VPython to get you model built and view- > point placed, and the tweak the POV-ray code to get pretty output. > > --Scott David Daniels > [EMAIL PROTECTED] > -- > http://mail.python.org/mailman/listinfo/python-list > Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: Adding Worksheets to an Excel Workbook
Hi Wesley, * wesley chun <[EMAIL PROTECTED]> wrote: >> just a small OT question coming from a linux openoffice >> system... >> >> Does there exist something similar for powerpoint? Would be >> nice, if anybody can direct me to more examples... > > > fabian, > > see below for a PP example. you mentioned you were coming from a > linux OOo system... are you trying to do COM stuff with OOo? i'm not > familiar with it, but since they do support > some level of VB-like scripting, i don't believe it's out of the question. > > one thing that i did forget to mention in my earlier message is that i > use static dispatch for these apps. if you did not go and run the > makepy utility, you would have to use dynamic dispatch, start your > apps with win32com.client.Dispatch(), or, using the same import > statement as below, win32.Dispatch(). > > anyway, here is pretty much the same script as i sent earlier but for > PowerPoint instead of Excel (the book has small examples for each of > Excel, Word, PowerPoint, and Outlook): > > # based on ppoint.pyw in Core Python Programming, 2nd ed > > from time import sleep > import win32com.client as win32 > > def ppoint(): > ppoint = win32.gencache.EnsureDispatch('PowerPoint.Application') > pres = ppoint.Presentations.Add() > ppoint.Visible = True > > s1 = pres.Slides.Add(1, win32.constants.ppLayoutText) > sleep(1) > s1a = s1.Shapes[0].TextFrame.TextRange > s1a.Text = 'Python-to-PowerPoint Demo' > sleep(1) > s1b = s1.Shapes[1].TextFrame.TextRange > for i in range(3, 8): > s1b.InsertAfter("Line %d\r\n" % i) > sleep(1) > s1b.InsertAfter("\r\nTh-th-th-that's all folks!") > > sleep(5) > pres.Close() > ppoint.Quit() > > if __name__=='__main__': > ppoint() Thanks! I am not able to try it out yet, but as soon as I get access to my windows machine, I'll give it a try. Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Flushing standard input
Recently I came across a problem which I still can't solve on my own. Consider this small example: import sys import time time.sleep(3) print sys.stdin.flush() input = raw_input('Your input: ') print 'Your input: ', input While the script is sleeping I type in the word 'test1', so that it is printed on the console. Having slept for three seconds the script continues and wants me to type in another word 'test2' and I hit return. The output looks like this: [EMAIL PROTECTED] ~ [ 21:41:27 ] $ python test.py test1 test2 Your input: test1test2 Is there any way to flush the stdin buffer so that 'test1' is _not_ regarded as input? How could one solve this issue? Cheers, Fabian -- http://mail.python.org/mailman/listinfo/python-list
change keybindings for pygtk treeview
Hi, I am just testing pygtk/glade out and wonder, if I am able to change the keybindings. E.g. the treeview searches by default for the entries beginning with the typed keystroke; moving to the next row works as usual with the Down key. Now I would like to change the key bindings to e.g. 'j' to move to the next row (just like in vim) and to use a 'Ctrl' key combination to search for a certain word beginning with the typed key stroke. Is it anyhow possible with pygtk? Would be nice, if somebody can point my to a small example. Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: change keybindings for pygtk treeview
Hi, * Fabian Braennstroem <[EMAIL PROTECTED]> wrote: > Hi, > > I am just testing pygtk/glade out and wonder, if I am able > to change the keybindings. E.g. the treeview searches by > default for the entries beginning with the typed keystroke; > moving to the next row works as usual with the Down key. Now > I would like to change the key bindings to e.g. 'j' to move > to the next row (just like in vim) and to use a 'Ctrl' key > combination to search for a certain word beginning with the > typed key stroke. I just found out, that I am able to turn it of with 'treeview.set_enable_search(False)'. Works nice. An option would be, to toggle the searching function with some keystroke, e.g. 'Ctrl-s'. And set a key binding for the movement to 'j' and 'k' when the search mode is disabled. I think I could do it somehow with the 'accelgroup' function, but did not find enough information to get a clue out of it. Does anybody have an idea? In a small curses based file manager (lfm) there is an assignment of keybindings via a keytable keytable = { # movement ord('p'): 'cursor_up', ord('k'): 'cursor_up', ord('K'): 'cursor_up2', ord('P'): 'cursor_up', curses.KEY_UP: 'cursor_up', ord('n'): 'cursor_down', ord('j'): 'cursor_down', ord('J'): 'cursor_down2', ord('N'): 'cursor_down', ... Would that work in any way for a pygtk program too? Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
small python cgi webserver
Hi, I am looking for a small python script, which starts a small web server with python cgi support on a linux machine. I tried: #!/usr/bin/env python import sys from CGIHTTPServer import CGIHTTPRequestHandler import BaseHTTPServer class MyRequestHandler(CGIHTTPRequestHandler): # In diesem Verzeichnis sollten die CGI-Programme stehen: cgi_directories=["/home/fab/Desktop/cgi-bin"] def run(): # 8000=Port-Nummer # --> http://localhost:8000/ # Fuer http://localhost/ # Port-Nummer auf 80 setzen httpd=BaseHTTPServer.HTTPServer(('', 8000), MyRequestHandler) httpd.serve_forever() if __name__=="__main__": print "Starting Server" run() but when I want to test a small python cgi test file: #!/usr/bin/python # -*- coding: UTF-8 -*- # Debugging fÃŒr CGI-Skripte 'einschalten' import cgitb; cgitb.enable() print "Content-Type: text/html;charset=utf-8\n" print "Hello World!" I just get the text and not the html output. The file's mode is 755. Is there anything wrong with the webserver script or do I do something completely wrong? Maybe, you have a different webserver script? Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: small python cgi webserver
Hi, * ArdPy <[EMAIL PROTECTED]> wrote: > > Fabian Braennstroem wrote: >> Hi, >> >> I am looking for a small python script, which starts a small >> web server with python cgi support on a linux machine. >> >> I tried: >> >> >> #!/usr/bin/env python >> import sys >> from CGIHTTPServer import CGIHTTPRequestHandler >> import BaseHTTPServer >> >> class MyRequestHandler(CGIHTTPRequestHandler): >> # In diesem Verzeichnis sollten die CGI-Programme stehen: >> cgi_directories=["/home/fab/Desktop/cgi-bin"] >> >> >> def run(): >> # 8000=Port-Nummer >> # --> http://localhost:8000/ >> # Fuer http://localhost/ >> # Port-Nummer auf 80 setzen >> httpd=BaseHTTPServer.HTTPServer(('', 8000), MyRequestHandler) >> httpd.serve_forever() >> >> if __name__=="__main__": >> print "Starting Server" >> run() >> >> but when I want to test a small python cgi test file: >> >> >> #!/usr/bin/python >> # -*- coding: UTF-8 -*- >> >> # Debugging für CGI-Skripte 'einschalten' >> import cgitb; cgitb.enable() >> >> print "Content-Type: text/html;charset=utf-8\n" >> print "Hello World!" >> >> I just get the text and not the html output. The file's mode >> is 755. >> >> Is there anything wrong with the webserver script or do I do >> something completely wrong? Maybe, you have a different >> webserver script? >> >> Greetings! >> Fabian > > Probably the server is not executing your CGI script. If it is the > Apache web server that you are using then just ensure the following > settings in your /etc/httpd/conf/httpd.conf file is exactly like > following: > > > AllowOverride None > Options ExecCGI > Order allow,deny > Allow from all > Maybe, I understood something wrong, but I thought that the above 'webserver' script would replace apache in my case; at least I hoped!? Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: small python cgi webserver
Hi Norbert, * Norbert Kaufmann <[EMAIL PROTECTED]> wrote: > Fabian Braennstroem wrote: > [...] >> >> Maybe, I understood something wrong, but I thought that the >> above 'webserver' script would replace apache in my case; at >> least I hoped!? >> > > It does. The 'ServerRoot' and 'DocumentRoot' directories are the > directories you are starting your webserver in. > Create a 'cgi' directory inside this and consider that you have to name > it in the serverscript in relation to the serverroot! > > > cgi_directories=["/home/fab/Desktop/cgi-bin"] > > > This means you have to start your server inside directory '/'. I tried this, but it does not help ... a wait, the leading '/' is the problem. Thanks! > > If you start your server in your home dir '/home/fab' then you have to > name your cgi_directories ['/Desktop/cgi-bin']. > > In your response (cgi-script) you have to divide the header from the > content '\r\n\r\n'. I am not sure, what that means!? ... but it works :-) Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
regex module, or don't work as expected
Howdy, i have the following regex "iface lo[\w\t\n\s]+(?=(iface)|$)" If "iface" don't follow after the regex "iface lo[\w\t\n\s]" the rest of the text should be selected. But ?=(iface) is ignored, it is always the whole texte selected. What is wrong? many thanks greetings Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: regex module, or don't work as expected
Hello Marc, thank you for your answer. Marc 'BlackJack' Rintsch wrote: > In <[EMAIL PROTECTED]>, Fabian Holler wrote: >> i have the following regex "iface lo[\w\t\n\s]+(?=(iface)|$)" >> >> If "iface" don't follow after the regex "iface lo[\w\t\n\s]" the rest of >> the text should be selected. >> But ?=(iface) is ignored, it is always the whole texte selected. >> What is wrong? > > The ``+`` after the character class means at least one of the characters > in the class or more. If you have a text like: Yes thats right, but that isn't my problem. The problem is in the "(?=(iface)|$)" part. I have i.e. the text: "auto lo eth0 iface lo inet loopback bla blub iface eth0 inet dhcp hostname debian" My regex should match the marked text. But it matchs the whole text starting from iface. If there is only one iface entry, the whole text starting from iface should be matched. greetings Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: radio buttons in curses
Hi Steve, * Steve Holden <[EMAIL PROTECTED]> wrote: > Fabian Braennstroem wrote: >> Sorry, me again... >> Does nobody have an idea or is it to stupid? >> >> * Fabian Braennstroem <[EMAIL PROTECTED]> wrote: >> >>>Hi, >>> >>>I want to add some radio and check buttons to my curses >>>script. As I understand it, there are no buttons in the >>>'basic' curses module. Now, I found the curses-extra module, >>>but I not able to download and install it. >>> >>>Does anybody have an idea, where I can download the module >>>or, even better, how I can create radio and check buttons >>>with the 'ordinary' curses module? Would be nice... >>> >>>Greetings! >>> Fabian >>> >>>-- >>>http://mail.python.org/mailman/listinfo/python-list >>> >> >> >> Greetings! >> Fabian >> > Sounding a bit like a "no", looks like. Did you Google much? Yes, it looks like this ... actually, I did google and found out that it does not work, so that I am looking for curses-extra. Maybe, somebody has a copy and could send me one? Would be nice! Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: radio buttons in curses
Hi Fredrik, * Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Fabian Braennstroem wrote: > >> Does nobody have an idea or is it to stupid? > > have you looked at: > > http://excess.org/urwid/ Thanks! I found this too and it seems to be helpful... Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
latex openoffice converter
Hi, I would like to use python to convert 'simple' latex documents into openoffice format. Maybe, anybody has done something similar before and can give me a starting point!? Would be nice to hear some hints! Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: latex openoffice converter
Hi to both, thanks! I'll try them ... * Fabian Braennstroem <[EMAIL PROTECTED]> wrote: > Hi, > > I would like to use python to convert 'simple' latex > documents into openoffice format. Maybe, anybody has done > something similar before and can give me a starting point!? > Would be nice to hear some hints! > > Greetings! > Fabian > > -- > http://mail.python.org/mailman/listinfo/python-list > Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
python gtk based file manager
Hi, I am looking for a file manager based on pygtk. It seems that there does not exist any!? Maybe, someone has a hint or already some starting code lines for such a 'thing'!? Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: python gtk based file manager
Hi, * faulkner <[EMAIL PROTECTED]> wrote: > http://www.google.com/search?q=emelfm2 > awesome file manager written in C using gtk. > i've been meaning to write something like emelfm in pygtk, but emelfm > already exists... Thanks! I found it too, but I am looking for a python version ... python seems to me a lot easier than C, esp. for adjusting and adding some functions for my daily use. I found wxPyAtol, which could be a good base, but unfortunately there is no wx installed at my office machine :-( > > Fabian Braennstroem wrote: >> Hi, >> >> I am looking for a file manager based on pygtk. It seems >> that there does not exist any!? Maybe, someone has a hint or >> already some starting code lines for such a 'thing'!? >> >> Greetings! >> Fabian > > -- > http://mail.python.org/mailman/listinfo/python-list > Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Splitting device addresses into parts
I often have to deal with strings like "PCI:2:3.0" or "PCI:3.4:0" and need the single numbers as tuple (2, 3, 0) or (3, 4, 0). Is there any simple way to achieve this? So far I am using regular expressions but I would like to avoid them ... Regards, Fabian Steiner -- http://mail.python.org/mailman/listinfo/python-list
Re: Splitting device addresses into parts
Bruno Desthuilliers wrote: > Fabian Steiner wrote: >> I often have to deal with strings like "PCI:2:3.0" or "PCI:3.4:0" and >> need the single numbers as tuple (2, 3, 0) or (3, 4, 0). Is there any >> simple way to achieve this? So far I am using regular expressions but I >> would like to avoid them ... > > devices = ["PCI:2:3.0", "PCI:3.4:0"] > for d in device: > nums = tuple(map(int, d.split(':')[1:])) > print "for ", d, " : ", nums Unfortunately, this doesn't work (even if I correct your typos) since the delimeter isn't necessary a colon - that's exactly the difficulty I am trying to solve. Regards, Fabian Steiner -- http://mail.python.org/mailman/listinfo/python-list
Re: Splitting device addresses into parts
[EMAIL PROTECTED] wrote: > This may be a rare case where regular expressions are not a horrible, > self-defeating idea. Something like: > > delimiter = re.compile("[:\.]") > delimiter.split("PCI:2:3.0") > ...and then ignore the first entry, and map int the rest. > Alternatively, if the delimiters can really be anything, and if there > are no numbers in the first space ("PCI"), then maybe this approach: Thank you, this solution seems to be quite satisfying :-) Regards, Fabian Steiner -- http://mail.python.org/mailman/listinfo/python-list
python 2.5 install from source problem
Hi, I just tried to install python 2.5 from source on my ScienticLinux (Redhat Clone) machine. It seems to work without any problem, at least I am able to run some of my old scripts. I installed it with './configure --prefix=/opt/python make make altinstall', but now for a 'vtk' installation which needs the python libraries I am not able to find a file like 'libpython2.5.so.*', which I think should be produced (at least at my office's machine (redhat) it is there). I just can find a 'libpython2.5.a' file ... Do I do something wrong? Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: python 2.5 install from source problem
Hi Martin, * Martin v. Löwis <[EMAIL PROTECTED]> wrote: > Fabian Braennstroem schrieb: >> I just tried to install python 2.5 from source on my >> ScienticLinux (Redhat Clone) machine. It seems to work >> without any problem, at least I am able to run some of my >> old scripts. I installed it with './configure >> --prefix=/opt/python make make altinstall', but now for a >> 'vtk' installation which needs the python libraries I am not >> able to find a file like 'libpython2.5.so.*', which I think >> should be produced (at least at my office's machine (redhat) >> it is there). I just can find a 'libpython2.5.a' file ... >> >> Do I do something wrong? > > I'd say it is a bug in vtk that it requires libpython2.5.so.*. > However, to work-around, you can configure Python with > --enable-shared. Make sure to set LD_LIBRARY_PATH or LD_RUN_PATH > appropriately. Thanks a lot! Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
General Type Checks (int, str, tuple, etc.)
Hello! So far, I am using something like »if isinstance(var, int):« to determine, whether var's value is an integer. Now I would like to know if there is any better possibility to do such general checks or may a construct with isinstance() even fail in certain cases? Cheers, Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: PyQt: QListView how to retrieve selected items?
Hi! Sorry for adopting your post for my own question, but since it is related to PyQT I think it's ok: Does anybody of you know where the openbook »GUI Programming with Python: QT Edition« has gone? It's not available any more: http://www.opendocs.org/pyqt/ points now to a non-existing site. So far, I also couldn't find any other site to have a look at the online version. Any hints are welcome! -- http://mail.python.org/mailman/listinfo/python-list
PyQt and Threading to update a dialog?
Hello! I have just written a MyDialog class which is derived from the orginial QDialog class. MyDialog only possesses a QLabel and a QPushButton. Now I would like to get the QLabel updated every second so that it displays the current time. I think I will have to work with Threads in order to achieve this aim, but so far I didn't succeed in doing it because I couldn't find any examples. Could anyone give me some hints or a piece of code? Cheers, Fabian Steiner -- http://mail.python.org/mailman/listinfo/python-list
PyQT: QDialog and QMainWindow interacting with each other
Hello! I have got a QMainWindow with a QListView, in which the different entries of a database are shown to the user. Moreover it has got a QPushButton, so that another QDialog can be opened where the user is able to add a new entry: ... self.connect(self.btnNew, SIGNAL('clicked()'), self.openNewDialog) ... def openNewDialog(self): dialog = MyDialog(self) dialog.show() self.showListViewItems() # this line isn't recognized MyDialog is closed by calling MyDialog.accept(). What can I do so that self.showListViewItems() is called after MyDialog has been closed? Thank you for any input! Cheers, Fabian Steiner -- http://mail.python.org/mailman/listinfo/python-list
Printing a file
Hello! I am currently working on an application where the user is able to create new worksheets and to delete existing ones. All of these worksheets have the same structure (--> template?), only some values should be changed. A minimal example would be something like this: Name: ... Role: Address: The values are stored in a SQLite database. Now I would like to offer the possibility to print out a single record on a DinA4 paper. In order to do this, the dots (...) above of course have to be replaced by the current record's values and the different parts have to fit on one page. Unfortunately I don't know how to realize this, since also some images and different boxes should be printed out. As the whole application is based on QT, QPrinter might be used, but I couldn't find any examples how to use it. What do you suggest? Which format should the template have? (XML, etc.?) Any hints appreciated! Cheers, Fabian Steiner -- http://mail.python.org/mailman/listinfo/python-list
Re: PyQT: QDialog and QMainWindow interacting with each other
Hi Kai! Kai Teuber wrote: > Hi Fabian, > > override the accept() method and call self.showListViewItems() there. > But remember to call QDialog.accept() at the end. > > def accept( self ): > self.showListViewItems() > QDialog.accept( self ) Thank you very much, I got it working :-) Cheers, Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: Printing a file
Hi! Thank you so far, but now I got stuck again :-/ Jeremy Sanders wrote: > QPrinter is easy to use. You just draw to the page the same way as you talk > to the screen with a QPainter. > > prnt = qt.QPrinter() > # you can also vary options like colour, doc name, dpi here > > # display dialog box to user (you can actually leave this out) > if prnt.setup(): > painter = qt.QPainter() > painter.begin(printer) > # do stuff to draw to painter > painter.end(printer) > # do this between each page > printer.newPage() This is what I have so far: app = QApplication(sys.argv) printer = QPrinter(QPrinter.PrinterResolution) if printer.setup(): printer.setPageSize(printer.A4) painter = QPainter(printer) metrics = QPaintDeviceMetrics(painter.device()) marginHeight = 6 marginWidth = 8 body = QRect(marginWidth, marginHeight, metrics.widthMM() - 2 * marginWidth, metrics.heightMM() - 2 * marginHeight) painter.drawRect(body) painter.end() Doing so I hoped to get a rectangle which is as big as an A4 paper (with a small border), but unfortunately it is much smaller. Moreover, I ask myself whether it is necessary that in order to write text on the paper, I always have to pass the proper x, y values to QPainter.drawText(). Isn't there any other possibility? How do I get these values? Thanks in advance, Fabian Steiner -- http://mail.python.org/mailman/listinfo/python-list
Re: Printing a file
David Boddie wrote: > Sorry about that. I must have just skipped over the setup() call in > your code. If you're creating highly customized content then I think > you'll always need to think about getting the pages to the printer in > the right order. > > For rich text documents, there's code that does this in the Qt 3 text > drawing demo (see the filePrint() method in the > examples/demo/textdrawing/textedit.cpp file). > > In Qt 4, the demos/textedit demo does this with a lot less code. > > Or are you think of something else? Thank you very much for this hint! Thanks to this example I was able to print out my first pages :) But some questions still remain. At the moment I am using QSimpleRichtext and a personal HTML-File. I had a look at the example.html of textedit.cpp (/usr/share/doc/qt-4.1.1/demos/textedit) and found out that it contains quite a lot of proprietary HTML elements, attributes and CSS style definitions. So far I didn't even know that QSimpleRichText even supports CSS since I couldn't find anything related to this point in the official docs (--> e.g. QStylesheet). Is there any tool out there with which I can write those special HTML files? I am quite familiar with HTML and CSS but I don't want to waste my time with that. Regards, Fabian Steiner -- http://mail.python.org/mailman/listinfo/python-list
chmod directories recursively
Hello! As far as I can see os.chmod() doesn't adjust permissions on directories recusively. Is there any other possibility to achieve this aim except for calling os.system('chmod -R /dir') directly? Thanks, Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: chmod directories recursively
Jennifer Thacher wrote: > Fabian Steiner wrote: >> As far as I can see os.chmod() doesn't adjust permissions on directories >> recusively. Is there any other possibility to achieve this aim except for >> calling os.system('chmod -R /dir') directly? >> >> Thanks, >> Fabian > > Check out os.path.walk. Thanks for your advice. This pointed me into the right direction. For those who are interested the function passed to os.path.walk looks like this: def _chownRecursive(arg, dirname, fnames): os.chown(dirname, arg[0], arg[1]) for file in fnames: os.chown(os.path.join(dirname, file), arg[0], arg[1]) Fabian -- http://mail.python.org/mailman/listinfo/python-list
help with Python C-API, tuple object
Hi, sorry for the rather basic question but I've searched everywhere and don't find an answer. I want to call PyObject_CallObject from the Python C-API and pass a tuple I've created from a C-array How can I pass the tuple as an object rather then having to declare the python function with the number of arguments equal to the no of elements in the tuple? Example: C-Code fragment: PyObject *pArgs = PyTuple_New(3); //module is imported and function object is build and checked for (i=0; i<3; i++){ pInt = PyInt_FromLong(i); error = PyTuple_SetItem(pArgs, i, pInt); } pValue=PyObject_CallObject(pFunc, pArgs);//returns NULL!!! Python Script: def length(a): length = len(a) return length -- http://mail.python.org/mailman/listinfo/python-list
Re: help with Python C-API, tuple object
On May 12, 2:49 pm, "Carsten Haese" <[EMAIL PROTECTED]> wrote: > On 11 May 2007 21:11:06 -0700, fabian.conrad wrote > > > Hi, > > sorry for the rather basic question but I've searched everywhere and > > don't find an answer. > > I want to call PyObject_CallObject from the Python C-API and pass a > > tuple I've created from a C-array > > > How can I pass the tuple as an object rather then having to declare > > the python function with the number of arguments equal to the no of > > elements in the tuple? > > The documentation athttp://docs.python.org/api/object.htmllists various Call > flavors. The one you chose will unpack the tuple as if you called > pFunc(*pArgs), which results in the undesired behavior of pFunc receiving > three arguments. You want it to receive one argument that is the tuple pArgs. > > One (bad) way of achieving this would be to build another tuple of size one, > stick pArgs into it, and pass that size-one tuple to PyObject_CallObject. A > better way is to use PyObject_CallFunctionObjArgs. If I'm not mistaken, you'll > want something like > > pValue = PyObject_CallFunctionObjArgs(pFunc, pArgs, NULL); > > Hope this helps, > > -- > Carsten Haesehttp://informixdb.sourceforge.net Thanks billions!!! Works perfect, the world would be a lot worse without Pro's like you guys helping newbies like me ;-) -- http://mail.python.org/mailman/listinfo/python-list
track cpu usage of linux application
Hi, I would like to track the cpu usage of a couple of programs using python. Maybe it works somehow with piping 'top' to python read the cpu load for a greped application and clocking the the first and last appearence. Is that a good approach or does anyone have a more elegant way to do that? Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: track cpu usage of linux application
Hi, thanks to both! I will take a look at the proc files! * James T. Dennis <[EMAIL PROTECTED]> wrote: > Fabian Braennstroem <[EMAIL PROTECTED]> wrote: >> Hi, > >>I would like to track the cpu usage of a couple of >>programs using python. Maybe it works somehow with >>piping 'top' to python read the cpu load for a greped >>application and clocking the the first and last >>appearence. Is that a good approach or does anyone have >>a more elegant way to do that? > >> Greetings! >> Fabian > > If you're on a Linux system you might be far better accessing > the /proc/$PID/stat files directly. The values you'd find therein > are documented: > > http://www.die.net/doc/linux/man/man5/proc.5.html > > (among other places). > > Of course you could write you code to look for file and fall back > to use the 'ps' command if it fails. In addition you can supply > arguments to the 'ps' command to limit it to reporting just on the > process(es) in which you are interested ... and to eliminate the > header line and irrelevant columns of output. Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
vte examples and installation
Hi, I am looking for simple vte examples mainly for pygtk. Can anyone point me in the right direction or is there a better terminal emulation for pygtk? It would be nice, if there exist a good howto for installing vte up for the use of python; esp. for an old redhat/scientific linux machine... I am a little bit confused!? Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
extract text from log file using re
Hi, I would like to delete a region on a log file which has this kind of structure: #--flutest 498 1.0086e-03 2.4608e-04 9.8589e-05 1.4908e-04 8.3956e-04 3.8560e-03 4.8384e-02 11:40:01 499 499 1.0086e-03 2.4608e-04 9.8589e-05 1.4908e-04 8.3956e-04 3.8560e-03 4.8384e-02 11:40:01 499 reversed flow in 1 faces on pressure-outlet 35. Writing "/home/gcae504/SCR1/Solververgleich/Klimakruemmer_AK/CAD/Daimler/fluent-0500.cas"... 5429199 mixed cells, zone 29, binary. 11187656 mixed interior faces, zone 30, binary. 20004 triangular wall faces, zone 31, binary. 1104 mixed velocity-inlet faces, zone 32, binary. 133638 triangular wall faces, zone 33, binary. 14529 triangular wall faces, zone 34, binary. 1350 mixed pressure-outlet faces, zone 35, binary. 11714 mixed wall faces, zone 36, binary. 1232141 nodes, binary. 1232141 node flags, binary. Done. Writing "/home/gcae504/SCR1/Solververgleich/Klimakruemmer_AK/CAD/Daimler/fluent-0500.dat"... Done. 500 1.0049e-03 2.4630e-04 9.8395e-05 1.4865e-04 8.3913e-04 3.8545e-03 1.3315e-01 11:14:10 500 reversed flow in 2 faces on pressure-outlet 35. 501 1.0086e-03 2.4608e-04 9.8589e-05 1.4908e-04 8.3956e-04 3.8560e-03 4.8384e-02 11:40:01 499 #-- I have a small script, which removes lines starting with '(re)versed', '(i)teration' and '(t)urbulent' and put the rest into an array: # -- plot residuals import re filename="flutest" reversed_flow=re.compile('^\ re') turbulent_viscosity_ratio=re.compile('^\ tu') iteration=re.compile('^\ \ i') begin_of_res=re.compile('>\ \ \ i') end_of_res=re.compile('^\ ad') begin_of_writing=re.compile('^\Writing') end_of_writing=re.compile('^\Done') end_number=0 begin_number=0 n = 0 for line in open(filename).readlines(): n = n + 1 if begin_of_res.match(line): begin_number=n+1 print "Line Number (begin): " + str(n) if end_of_res.match(line): end_number=n print "Line Number (end): " + str(n) if begin_of_writing.match(line): begin_w=n+1 print "BeginWriting: " + str(n) print "HALLO" if end_of_writing.match(line): end_w=n+1 print "EndWriting: " +str(n) if n > end_number: end_number=n print "Line Number (end): " + str(end_number) n = 0 array = [] array_dummy = [] array_mapped = [] mapped = [] mappe = [] n = 0 for line in open(filename).readlines(): n = n + 1 if (begin_number <= n) and (end_number > n): #if (begin_w <= n) and (end_w > n): if not reversed_flow.match(line) and not iteration.match(line) and not turbulent_viscosity_ratio.match(line): m=(line.strip().split()) print m if len(m) > 0: #print len(m) laenge_liste=len(m) #print len(m) mappe.append(m) #--end plot residuals- This works fine ; except for the region with the writing information: #-writing information - Writing "/home/fb/fluent-0500.cas"... 5429199 mixed cells, zone 29, binary. 11187656 mixed interior faces, zone 30, binary. 20004 triangular wall faces, zone 31, binary. 1104 mixed velocity-inlet faces, zone 32, binary. 133638 triangular wall faces, zone 33, binary. 14529 triangular wall faces, zone 34, binary. 1350 mixed pressure-outlet faces, zone 35, binary. 11714 mixed wall faces, zone 36, binary. 1232141 nodes, binary. 1232141 node flags, binary. Done. # ---end writing information --- Does anyone know, how I can this 'writing' stuff too? The matchingIt occurs a lot :-( Regards! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: extract text from log file using re
me again... I should describe it better: the result should be an array with just: 498 1.0086e-03 2.4608e-04 9.8589e-05 1.4908e-04 8.3956e-04 3.8560e-03 4.8384e-02 11:40:01 499 499 1.0086e-03 2.4608e-04 9.8589e-05 1.4908e-04 8.3956e-04 3.8560e-03 4.8384e-02 11:40:01 499 500 1.0049e-03 2.4630e-04 9.8395e-05 1.4865e-04 8.3913e-04 3.8545e-03 1.3315e-01 11:14:10 500 501 1.0086e-03 2.4608e-04 9.8589e-05 1.4908e-04 8.3956e-04 3.8560e-03 4.8384e-02 11:40:01 499 as field values. Fabian Braennstroem schrieb am 09/13/2007 09:09 PM: > Hi, > > I would like to delete a region on a log file which has this > kind of structure: > > > #--flutest >498 1.0086e-03 2.4608e-04 9.8589e-05 1.4908e-04 > 8.3956e-04 3.8560e-03 4.8384e-02 11:40:01 499 >499 1.0086e-03 2.4608e-04 9.8589e-05 1.4908e-04 > 8.3956e-04 3.8560e-03 4.8384e-02 11:40:01 499 > reversed flow in 1 faces on pressure-outlet 35. > > Writing > "/home/gcae504/SCR1/Solververgleich/Klimakruemmer_AK/CAD/Daimler/fluent-0500.cas"... > 5429199 mixed cells, zone 29, binary. > 11187656 mixed interior faces, zone 30, binary. >20004 triangular wall faces, zone 31, binary. > 1104 mixed velocity-inlet faces, zone 32, binary. > 133638 triangular wall faces, zone 33, binary. >14529 triangular wall faces, zone 34, binary. > 1350 mixed pressure-outlet faces, zone 35, binary. >11714 mixed wall faces, zone 36, binary. > 1232141 nodes, binary. > 1232141 node flags, binary. > Done. > > > Writing > "/home/gcae504/SCR1/Solververgleich/Klimakruemmer_AK/CAD/Daimler/fluent-0500.dat"... > Done. > >500 1.0049e-03 2.4630e-04 9.8395e-05 1.4865e-04 > 8.3913e-04 3.8545e-03 1.3315e-01 11:14:10 500 > > reversed flow in 2 faces on pressure-outlet 35. >501 1.0086e-03 2.4608e-04 9.8589e-05 1.4908e-04 > 8.3956e-04 3.8560e-03 4.8384e-02 11:40:01 499 > > #-- > > I have a small script, which removes lines starting with > '(re)versed', '(i)teration' and '(t)urbulent' and put the > rest into an array: > > # -- plot residuals > import re > filename="flutest" > reversed_flow=re.compile('^\ re') > turbulent_viscosity_ratio=re.compile('^\ tu') > iteration=re.compile('^\ \ i') > > begin_of_res=re.compile('>\ \ \ i') > end_of_res=re.compile('^\ ad') > > begin_of_writing=re.compile('^\Writing') > end_of_writing=re.compile('^\Done') > > end_number=0 > begin_number=0 > > > n = 0 > for line in open(filename).readlines(): > n = n + 1 > if begin_of_res.match(line): > begin_number=n+1 > print "Line Number (begin): " + str(n) > > if end_of_res.match(line): > end_number=n > print "Line Number (end): " + str(n) > > if begin_of_writing.match(line): > begin_w=n+1 > print "BeginWriting: " + str(n) > print "HALLO" > > if end_of_writing.match(line): > end_w=n+1 > print "EndWriting: " +str(n) > > if n > end_number: > end_number=n > print "Line Number (end): " + str(end_number) > > > > > > n = 0 > array = [] > array_dummy = [] > array_mapped = [] > > mapped = [] > mappe = [] > > n = 0 > for line in open(filename).readlines(): > n = n + 1 > if (begin_number <= n) and (end_number > n): > #if (begin_w <= n) and (end_w > n): > if not reversed_flow.match(line) and not > iteration.match(line) and not > turbulent_viscosity_ratio.match(line): > m=(line.strip().split()) > print m > if len(m) > 0: > #print len(m) > laenge_liste=len(m) > #print len(m) > mappe.append(m) > > > #--end plot > residuals- > > This works fine ; except for the region with the writing > information: > > #-writing information > - > Writing "/home/fb/fluent-0500.cas"... > 5429199 mixed cells, zone 29, binary. > 11187656 mixed interior faces, zone 30, binary. >20004 triangular wall faces, zone 31, binary. > 1104 mixed velocity-inlet faces, zone 32, binary. > 133638 triangular wall faces, zone 33, binary. >14529 triangular wall faces, zone 34, binary. > 1350 mixed pressure-outlet faces, zone 35, binary. >11714 mixed wall faces, zone 36, binary. > 1232141 nodes, binary. > 1232141 node flags, binary. > Done. > # ---end writing information --- > > Does anyone know, how I can this 'writing' stuff too? The > matchingIt occurs a lot :-( > > Regards! > Fabian > -- http://mail.python.org/mailman/listinfo/python-list
pattern search
Hi, I wrote a small gtk file manager, which works pretty well. Until now, I am able to select different file (treeview entries) just by extension (done with 'endswith'). See the little part below: self.pathlist1=[ ] self.patternlist=[ ] while iter: #print iter value = model.get_value(iter, 1) #if value is what I'm looking for: if value.endswith("."+ pattern): selection.select_iter(iter) selection.select_path(n) self.pathlist1.append(n) self.patternlist.append(value) iter = model.iter_next(iter) #print value n=n+1 Now, I would like to improve it by searching for different 'real' patterns just like using 'ls' in bash. E.g. the entry 'car*.pdf' should select all pdf files with a beginning 'car'. Does anyone have an idea, how to do it? Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: pattern search
Hi to all, Wojciech Mu?a schrieb am 03/27/2007 03:34 PM: > Fabian Braennstroem wrote: >> Now, I would like to improve it by searching for different 'real' >> patterns just like using 'ls' in bash. E.g. the entry >> 'car*.pdf' should select all pdf files with a beginning 'car'. >> Does anyone have an idea, how to do it? > > Use module glob. Thanks for your help! glob works pretty good, except that I just deleted all my lastet pdf files :-( Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: pattern search
Hi, Gabriel Genellina schrieb am 03/27/2007 10:09 PM: > En Tue, 27 Mar 2007 18:42:15 -0300, Diez B. Roggisch <[EMAIL PROTECTED]> > escribió: > >> Paul McGuire schrieb: >>> On Mar 27, 10:18 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: >>>> Fabian Braennstroem wrote: >>>>> while iter: >>>>> value = model.get_value(iter, 1) >>>>> if value.endswith("."+ pattern): [...] >>>>> >>>>> Now, I would like to improve it by searching for different 'real' >>>>> patterns just like using 'ls' in bash. E.g. the entry >>>>> 'car*.pdf' should select all pdf files with a beginning 'car'. >>>>> Does anyone have an idea, how to do it? > >>>> Use regular expressions. They are part of the module "re". And if you >>>> use them, ditch your code above, and make it just search for a pattern >>>> all the time. Because the above is just the case of >>>> *.ext > >>> The glob module is a more direct tool based on the OP's example. The >>> example he gives works directly with glob. To use re, you'd have to >>> convert to something like "car.*\.pdf", yes? > >> I'm aware of the glob-module. But it only works on files. I was under >> the impression that he already has a list of files he wants to filter >> instead of getting it fresh from the filesystem. > > In that case the best way would be to use the fnmatch module - it already > knows how to translate from car*.pdf into the right regexp. (The glob > module is like a combo os.listdir+fnmatch.filter) I have a already a list, but I 'glob' looked so easy ... maybe it is faster to use fnmatch. When I have time I try it out... Thanks! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: pattern search
Hi Paul, Paul McGuire schrieb am 03/27/2007 07:19 PM: > On Mar 27, 3:13 pm, Fabian Braennstroem <[EMAIL PROTECTED]> wrote: >> Hi to all, >> >> Wojciech Mu?a schrieb am 03/27/2007 03:34 PM: >> >>> Fabian Braennstroem wrote: >>>> Now, I would like to improve it by searching for different 'real' >>>> patterns just like using 'ls' in bash. E.g. the entry >>>> 'car*.pdf' should select all pdf files with a beginning 'car'. >>>> Does anyone have an idea, how to do it? >>> Use module glob. >> Thanks for your help! glob works pretty good, except that I just >> deleted all my lastet pdf files :-( >> >> Greetings! >> Fabian > > Then I shudder to think what might have happened if you had used > re's! :) A different feature it had was to copy the whole home-partition (about 19G) into one of its own directories ... the strange thing: it just needed seconds to do that and I did not have the permission to all files and directories! It was pretty strange! Hopefully it was no security bug in python... Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: extract text from log file using re
Hi to all, thanks for your help. The approach print '\r\n'.join([x.strip() for x in open('c:/flutest.txt') if 'e-0' in x]) works quite well :-) Greetings! Fabian Fabian Braennstroem schrieb am 09/13/2007 09:09 PM: > Hi, > > I would like to delete a region on a log file which has this > kind of structure: > > > #--flutest >498 1.0086e-03 2.4608e-04 9.8589e-05 1.4908e-04 > 8.3956e-04 3.8560e-03 4.8384e-02 11:40:01 499 >499 1.0086e-03 2.4608e-04 9.8589e-05 1.4908e-04 > 8.3956e-04 3.8560e-03 4.8384e-02 11:40:01 499 > reversed flow in 1 faces on pressure-outlet 35. > > Writing > "/home/gcae504/SCR1/Solververgleich/Klimakruemmer_AK/CAD/Daimler/fluent-0500.cas"... > 5429199 mixed cells, zone 29, binary. > 11187656 mixed interior faces, zone 30, binary. >20004 triangular wall faces, zone 31, binary. > 1104 mixed velocity-inlet faces, zone 32, binary. > 133638 triangular wall faces, zone 33, binary. >14529 triangular wall faces, zone 34, binary. > 1350 mixed pressure-outlet faces, zone 35, binary. >11714 mixed wall faces, zone 36, binary. > 1232141 nodes, binary. > 1232141 node flags, binary. > Done. > > > Writing > "/home/gcae504/SCR1/Solververgleich/Klimakruemmer_AK/CAD/Daimler/fluent-0500.dat"... > Done. > >500 1.0049e-03 2.4630e-04 9.8395e-05 1.4865e-04 > 8.3913e-04 3.8545e-03 1.3315e-01 11:14:10 500 > > reversed flow in 2 faces on pressure-outlet 35. >501 1.0086e-03 2.4608e-04 9.8589e-05 1.4908e-04 > 8.3956e-04 3.8560e-03 4.8384e-02 11:40:01 499 > > #-- > > I have a small script, which removes lines starting with > '(re)versed', '(i)teration' and '(t)urbulent' and put the > rest into an array: > > # -- plot residuals > import re > filename="flutest" > reversed_flow=re.compile('^\ re') > turbulent_viscosity_ratio=re.compile('^\ tu') > iteration=re.compile('^\ \ i') > > begin_of_res=re.compile('>\ \ \ i') > end_of_res=re.compile('^\ ad') > > begin_of_writing=re.compile('^\Writing') > end_of_writing=re.compile('^\Done') > > end_number=0 > begin_number=0 > > > n = 0 > for line in open(filename).readlines(): > n = n + 1 > if begin_of_res.match(line): > begin_number=n+1 > print "Line Number (begin): " + str(n) > > if end_of_res.match(line): > end_number=n > print "Line Number (end): " + str(n) > > if begin_of_writing.match(line): > begin_w=n+1 > print "BeginWriting: " + str(n) > print "HALLO" > > if end_of_writing.match(line): > end_w=n+1 > print "EndWriting: " +str(n) > > if n > end_number: > end_number=n > print "Line Number (end): " + str(end_number) > > > > > > n = 0 > array = [] > array_dummy = [] > array_mapped = [] > > mapped = [] > mappe = [] > > n = 0 > for line in open(filename).readlines(): > n = n + 1 > if (begin_number <= n) and (end_number > n): > #if (begin_w <= n) and (end_w > n): > if not reversed_flow.match(line) and not > iteration.match(line) and not > turbulent_viscosity_ratio.match(line): > m=(line.strip().split()) > print m > if len(m) > 0: > #print len(m) > laenge_liste=len(m) > #print len(m) > mappe.append(m) > > > #--end plot > residuals- > > This works fine ; except for the region with the writing > information: > > #-writing information > - > Writing "/home/fb/fluent-0500.cas"... > 5429199 mixed cells, zone 29, binary. > 11187656 mixed interior faces, zone 30, binary. >20004 triangular wall faces, zone 31, binary. > 1104 mixed velocity-inlet faces, zone 32, binary. > 133638 triangular wall faces, zone 33, binary. >14529 triangular wall faces, zone 34, binary. > 1350 mixed pressure-outlet faces, zone 35, binary. >11714 mixed wall faces, zone 36, binary. > 1232141 nodes, binary. > 1232141 node flags, binary. > Done. > # ---end writing information --- > > Does anyone know, how I can this 'writing' stuff too? The > matchingIt occurs a lot :-( > > Regards! > Fabian > -- http://mail.python.org/mailman/listinfo/python-list
open remote terminal
Hi, I would like to use python to start an terminal, e.g. xterm, and login on a remote machine using rsh or ssh. This could be done using 'xterm -e ssh machine', but after the login I would like to jump to a given directory. Does anyone have an idea how to do this with python? Regards! Fabian -- http://mail.python.org/mailman/listinfo/python-list
pyparsing batch file
Hi, me again :-) I would like to parse a small batch file: file/read-case kepstop.cas file/read-data keps1500.dat solve/monitors/residual/plot no solve/monitors/residual/print yes /define/boundary-conditions in velocity-inlet 10 0.1 0.1 no 1 it 500 wd keps1500_500.dat yes exit Right now, I use this little example: from pyparsing import * input = open("/home/fab/HOME/Dissertation/CFD/Fluent/Batch/fluent_batch", 'r') data = input.read() # # Define Grammars # integer = Word(nums) hexnums = Word(alphanums) end = Literal("\n").suppress() all = SkipTo(end) #threadname = dblQuotedString threadname_read_case = Literal("file/read-case") threadname_read_data= Literal("file/read-data") threadname_it = Literal("it") write_data=Literal("wd") cas_datei= Word(alphanums) iteration= Word(nums) write= Word(alphanums) file_read_data= "file/read-data " + hexnums.setResultsName("rd") logEntry = threadname_read_case.setResultsName("threadname") + cas_datei.setResultsName("cas_datei")+file_read_data logEntry = file_read_data logEntryNew = threadname_it.setResultsName("threadname") + iteration.setResultsName("iteration") logEntryWD = write_data.setResultsName("threadname") + write.setResultsName("write") # for tokens in logEntryNew.searchString(data): print print "Iteration Command=\t "+ tokens.threadname print "Number of Iterations=\t "+ tokens.iteration for x in tokens.condition: print x print 50*"-" for tokens in logEntryWD.searchString(data): print print "Write Data Command=\t "+ tokens.threadname print "Data File Name=\t "+ tokens.write for x in tokens.condition: print x print 50*"-" for tokens in logEntry.searchString(data): print print "no idea=\t "+ tokens.threadname print "Data File=\t "+ tokens.rd print for x in tokens.condition: print x print 50*"-" Unfortunately, it does not parse the whole file names with the underscore and I do not know yet, how I can access the line with 'define/boundary-conditions'. Every 'argument' of that command should become a separate python variable!? Does anyone have an idea, how I can achieve this!? Regards! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: open remote terminal
Hi Steve, Steve Holden wrote: > Fabian Braennstroem wrote: >> Hi, >> >> I would like to use python to start an terminal, e.g. xterm, and login on >> a remote machine using rsh or ssh. This could be done using 'xterm -e ssh >> machine', but after the login I would like to jump to a given directory. >> Does anyone have an idea how to do this with python? >> >> Regards! >> Fabian >> > pexpect would be the usual solution, I believe, if you could get it to > interact correctly with your virtual terminal. > >http://pexpect.sourceforge.net/ Thanks for the advice! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: pyparsing batch file
Hi Paul, Paul McGuire wrote: > On Oct 17, 4:47 pm, Fabian Braennstroem <[EMAIL PROTECTED]> wrote: > >> Unfortunately, it does not parse the whole file names with >> the underscore and I do not know yet, how I can access the >> line with 'define/boundary-conditions'. Every 'argument' of >> that command should become a separate python variable!? >> Does anyone have an idea, how I can achieve this!? >> Regards! >> Fabian > > You are trying to match "keps1500_500.dat" with the expression > "Word(alphanums)". Since the filename contains characters other than > alphas and numbers, you must add the remaining characters ("." and > "_") to the expression. Try changing: > > write= Word(alphanums) > > to: > > write= Word(alphanums+"._") > > > To help you to parse "/define/boundary-conditions in velocity-inlet 10 > 0.1 0.1 no 1", we would need to know just what these arguments are, > and what values they can take. I'll take a wild guess, and propose > this: > > real = Combine(integer + "." + integer) > defineBoundaryConditions = "/define/boundary-conditions" + \ > oneOf("in out inout")("direction") + \ > Word(alphanums+"-")("conditionName") + \ > integer("magnitude") + \ > real("initialX") + \ > real("initialY") + \ > oneOf("yes no")("optional") + \ > integer("normal") > > (Note I am using the new notation for setting results names, > introduced in 1.4.7 - simply follow the expression with ("name"), > instead of having to call .setResultsName.) > > And here is a slight modification to your printout routine, using the > dump() method of the ParseResults class: > > for tokens in defineBoundaryConditions.searchString(data): > print > print "Boundary Conditions = "+ tokens.conditionName > print tokens.dump() > print > print 50*"-" > > > prints: > > Boundary Conditions = velocity-inlet > ['/define/boundary-conditions', 'in', 'velocity-inlet', '10', '0.1', > '0.1', 'no', '1'] > - conditionName: velocity-inlet > - direction: in > - initialX: 0.1 > - initialY: 0.1 > - magnitude: 10 > - normal: 1 > - optional: no Great! Thanks for the very good explanation! Regards! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: open remote terminal
Fabian Braennstroem wrote: > Hi Steve, > > Steve Holden wrote: > >> Fabian Braennstroem wrote: >>> Hi, >>> >>> I would like to use python to start an terminal, e.g. xterm, and login >>> on a remote machine using rsh or ssh. This could be done using 'xterm -e >>> ssh machine', but after the login I would like to jump to a given >>> directory. Does anyone have an idea how to do this with python? >>> >>> Regards! >>> Fabian >>> >> pexpect would be the usual solution, I believe, if you could get it to >> interact correctly with your virtual terminal. >> >>http://pexpect.sourceforge.net/ I actually gave it a first very simple try: import pexpect child=pexpect.spawn('xterm') child.sendline('ls') Unfortunately nothing happens expect the start of xterm!? Does anyone have an idea, what I am doing wrong? Fabian -- http://mail.python.org/mailman/listinfo/python-list
ignoring chinese characters parsing xml file
Hi, I am parsing an XML file that includes chineses characters, like ^ �u�u啖啖才是�w.���扉L锍才是�� or ヘアアイロン... The problem is that I get an error like: UnicodeEncodeerror:'charmap' codec can't encode characters in position The thing is that I would like to ignore it and parse all the characters less these ones. So, could anyone help me? I suppose that I can catch an exception that ignores it or maybe use any function that detects this chinese characters and after that ignore them. Thanks!! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: ignoring chinese characters parsing xml file
Thanks Mark, the code is like this. The attrib name is the problem: from lxml import etree context = etree.iterparse("file.xml") for action, elem in context: if elem.tag == "weblog": print action, elem.tag , elem.attrib["name"],elem.attrib["url"], elem.attrib["rssUrl"] And the xml file like: http://weblogli.com " when="4" /> 22 Oct 2007 20:20:16 GMT, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]>: > > On Mon, 22 Oct 2007 21:24:40 +0200, Fabian López wrote: > > > I am parsing an XML file that includes chineses characters, like ^ > > uu啖啖才是w.扉L锍才是 or ヘアアイロン... The problem is that I get an error like: > > UnicodeEncodeerror:'charmap' codec can't encode characters in > > position.. > > You say you are *parsing* the file but this is an *encode* error. Parsing > means *decoding*. > > You have to show some code and the actual traceback to get help. Crystal > balls are not that reliable. ;-) > > Ciao, > Marc 'BlackJack' Rintsch > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: ignoring chinese characters parsing xml file
Thanks, I have tried all you told me. It was an error on print statement. So I decided to catch the exception if I had an UnicodeEncodeError, that is, if I had chinese/japanese characters because they don't interest to me and it worked. The strip_asian function of Ryan didn't work well here, but it's a good idea for next goals. Thanks a lot! Fabian 2007/10/23, limodou <[EMAIL PROTECTED]>: > > On 10/23/07, Stefan Behnel <[EMAIL PROTECTED]> wrote: > > Fabian López wrote: > > > Thanks Mark, the code is like this. The attrib name is the problem: > > > > > > from lxml import etree > > > > > > context = etree.iterparse("file.xml") > > > for action, elem in context: > > > if elem.tag == "weblog": > > > print action, elem.tag , elem.attrib["name"],elem.attrib > ["url"], > > > > The problem is the print statement. Looks like your terminal encoding > (that > > Python needs to encode the unicode string to) can't handle these unicode > > characters. > > > I agree. For Japanese, you should know the exactly encoding name, and > convert them, just like: > > print text.encoding('encoding') > > -- > I like python! > UliPad <>: http://code.google.com/p/ulipad/ > meide <>: http://code.google.com/p/meide/ > My Blog: http://www.donews.net/limodou > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: open remote terminal
Hi Rafael, Rafael Sachetto wrote: > Take a look at this documentation: > > http://pexpect.sourceforge.net/pxssh.html thanks for the link, but it actually looks to me almost like my little example... I somehow don't get it!? Any more hints? Fabian > >> >>> >> >> pexpect would be the usual solution, I believe, if you could get it to >> >> interact correctly with your virtual terminal. >> >> >> >>http://pexpect.sourceforge.net/ >> >> I actually gave it a first very simple try: >> >> import pexpect >> child=pexpect.spawn('xterm') >> child.sendline('ls') >> >> Unfortunately nothing happens expect the start of xterm!? Does anyone >> have an idea, what I am doing wrong? >> Fabian >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > -- http://mail.python.org/mailman/listinfo/python-list
How to test whether a host is reachable?
Hello! As the subject says I need to test whether a host computer in our network is reachable or not. At the moment I simply attempt to connect to a given port that is open when the machine is online: [...] sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: sock.connect(('192.168.0.100', 80)) except socket.error: print >>sys.stderr "Server offline" sock.close() [...] Now I am wondering if there isn't any better method which would be more general. In fact, I think of something like a python version of ping which only tries to send ICMP packets. However, I don't know what the code has to look like then. Any ideas or suggestions? Thanks, Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: How to test whether a host is reachable?
Hello! Chris Mellon wrote: > On 2/22/07, Fabian Steiner <[EMAIL PROTECTED]> wrote: >> [...] >> Now I am wondering if there isn't any better method which would be more >> general. In fact, I think of something like a python version of ping >> which only tries to send ICMP packets. However, I don't know what the >> code has to look like then. Any ideas or suggestions? >> > > This is the only reliable way of telling if you can communicate with a > service on a machine. A ping will tell you if it's connected to the > network, but not if it is actually providing any services. > > If you really want a ping, the common way is to just execute the systems > ping. Ok, obviously, my approach was already the best way to achive this aim. Thanks for you help, Fabian -- http://mail.python.org/mailman/listinfo/python-list
crawler in python and mysql
Hi, I would like to write a code that needs to crawl an url and take all the HTML code. I have noticed that there are different opensource webcrawlers, but they are very extensive for what I need. I only need to crawl an url, and don't know if it is so easy as using an html parser. Is it? Which libraries would you recommend me? Thanks!! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Efficient: put Content of HTML file into mysql database
Hi colegues, do you know the most efficient way to put the content of an html file into a mySQL database?Could it be this one?: 1.- I have the html document in my hard disk. 2.- Then I Open the file (maybe with fopen??) 3.- Read the content (fread or similar) 4.- Write all the content it in a SQL sentence. What happens if the html file is very big? Thanks! FAbian -- http://mail.python.org/mailman/listinfo/python-list
Re: Efficient: put Content of HTML file into mysql database
Thanks Jesse, we have a webserver with different domains and I need to crawl different urls so I decided first to download the file using : f = urllib.urlretrieve(url,'doc.html') And after that, I will read the content with all the HTML tags and save it on our database in order to work with this text. Is it enough? it is such an easy web crawler. Maybe I can save it without downloading the file, can I? Thanks Fabian 2007/11/19, Jesse Jaggars <[EMAIL PROTECTED]>: > > Fabian López wrote: > > Hi colegues, > > do you know the most efficient way to put the content of an html file > > into a mySQL database?Could it be this one?: > > 1.- I have the html document in my hard disk. > > 2.- Then I Open the file (maybe with fopen??) > > 3.- Read the content (fread or similar) > > 4.- Write all the content it in a SQL sentence. > > > > What happens if the html file is very big? > > > > > > Thanks! > > FAbian > > > > > I don't understand why you would want to store an entire static html > page in the database. All that accomplishes is adding the overhead of > calling MySQL too. > > If you want to serve HTML do just let your webserver serve HTML. > > Is there more to the situation that would help myself and others > understand why you want to do this? > -- http://mail.python.org/mailman/listinfo/python-list
regex problem with re and fnmatch
Hi, I would like to use re to search for lines in a files with the word "README_x.org", where x is any number. E.g. the structure would look like this: [[file:~/pfm_v99/README_1.org]] I tried to use these kind of matchings: #org_files='.*README\_1.org]]' org_files='.*README\_*.org]]' if re.match(org_files,line): Unfortunately, it matches all entries with "README.org", but not the wanted number!? After some splitting and replacing I am able to check, if the above file exists. If it does not, I start to search for it using the 'walk' procedure: for root, dirs, files in os.walk("/home/fab/org"): for name in dirs: dirs=os.path.join(root, name) + '/' for name in files: files=os.path.join(root, name) if fnmatch.fnmatch(str(files), "README*"): print "File Found" print str(files) break As soon as it finds the file, it should stop the searching process; but there is the same matching problem like above. Does anyone have any suggestions about the regex problem? Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: regex problem with re and fnmatch
Hi John, John Machin schrieb am 11/20/2007 09:40 PM: > On Nov 21, 8:05 am, Fabian Braennstroem <[EMAIL PROTECTED]> wrote: >> Hi, >> >> I would like to use re to search for lines in a files with >> the word "README_x.org", where x is any number. >> E.g. the structure would look like this: >> [[file:~/pfm_v99/README_1.org]] >> >> I tried to use these kind of matchings: >> #org_files='.*README\_1.org]]' >> org_files='.*README\_*.org]]' >> if re.match(org_files,line): > > First tip is to drop the leading '.*' and use search() instead of > match(). The second tip is to use raw strings always for your > patterns. > >> Unfortunately, it matches all entries with "README.org", but >> not the wanted number!? > > \_* matches 0 or more occurrences of _ (the \ is redundant). You need > to specify one or more digits -- use \d+ or [0-9]+ > > The . in .org matches ANY character except a newline. You need to > escape it with a \. > >>>> pat = r'README_\d+\.org' >>>> re.search(pat, 'README.org') >>>> re.search(pat, 'README_.org') >>>> re.search(pat, 'README_1.org') > <_sre.SRE_Match object at 0x00B899C0> >>>> re.search(pat, 'README_.org') > <_sre.SRE_Match object at 0x00B899F8> >>>> re.search(pat, 'README_Zorg') >>>> Thanks a lot, works really nice! >> After some splitting and replacing I am able to check, if >> the above file exists. If it does not, I start to search for >> it using the 'walk' procedure: > > I presume that you mean something like: """.. check if the above file > exists in some directory. If it does not, I start to search for it > somewhere else ...""" > >> for root, dirs, files in >> os.walk("/home/fab/org"): > >> for name in dirs: >> dirs=os.path.join(root, name) + '/' > > The above looks rather suspicious ... > for thing in container: > container = something_else > > What are you trying to do? > > >> for name in files: >> files=os.path.join(root, name) > > and again > >> if fnmatch.fnmatch(str(files), "README*"): > > Why str(name) ? > >> print "File Found" >> print str(files) >> break > > > fnmatch is not as capable as re; in particular it can't express "one > or more digits". To search a directory tree for the first file whose > name matches a pattern, you need something like this: > def find_one(top, pat): >for root, dirs, files in os.walk(top): > for fname in files: > if re.match(pat + '$', fname): > return os.path.join(root, fname) > > >> As soon as it finds the file, > > "the" file or "a" file??? > > Ummm ... aren't you trying to locate a file whose EXACT name you found > in the first exercise?? > > def find_it(top, required): >for root, dirs, files in os.walk(top): > if required in files: > return os.path.join(root, required) Great :-) Thanks a lot for your help... it can be so easy :-) Fabian -- http://mail.python.org/mailman/listinfo/python-list
lotus nsf to mbox
Hi, I am wondering, if anyone tried to convert lotus nsf mails to a mbox format using python!? It would be nice, if anyone has an idea, how to do it on a linux machine. Regards! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: lotus nsf to mbox
Hi to both, Dan Poirier schrieb am 12/15/2007 02:00 PM: > On Dec 15, 5:18 am, Fabian Braennstroem <[EMAIL PROTECTED]> wrote: >> I am wondering, if anyone tried to convert lotus nsf mails >> to a mbox format using python!? It would be nice, if anyone >> has an idea, how to do it on a linux machine. > > I've used jython to access notes databases through the Notes > Java APIs. Though I don't know if the Java APIs are available > on Linux. thanks for your ideas! I actually thought of something like a python parser, which just converts the nsf structure to an mbox; could that work!? Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: lotus nsf to mbox
Hi to all, thanks, I'll try your suggestions... Regards! Fabian Brian Munroe schrieb am 12/15/2007 07:10 PM: > On Dec 15, 11:04 am, Fabian Braennstroem <[EMAIL PROTECTED]> > wrote: > >> thanks for your ideas! I actually thought of something like >> a python parser, which just converts the nsf structure to an >> mbox; could that work!? >> > > Well, If you wish to go that route, I believe you will have to reverse > engineer the Notes Database binary structure because I've never seen > it published anywhere. My suggestion, if you can use a Windows > machine, just use the Lotus Notes COM Objects via the Python Win32 > bindings, as mentioned above. > > If you really need to do it from Linux and are lucky enough to be > running the IIOP task on your Domino server, then you could possibly > use CORBA. > -- http://mail.python.org/mailman/listinfo/python-list
problem with array and for loop
Hi, I have a 'simple' problem with a multidimension array in a for loop. It looks like this: wert= zeros([127,2]) wert1= zeros(127) m=1 l=1 for pos in [pos1,pos2,pos3]: for i in range(1,125): wert[l,m]= probe1.GetOutput().GetPointData().GetScalars().GetTuple1(i); #wert1[i]= probe1.GetOutput().GetPointData().GetScalars().GetTuple1(i); m=m+1; l=l+1; It works for the 1D 'wert1'. Does anyone have an idea? Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with array and for loop
Hi Robert, * Robert Kern <[EMAIL PROTECTED]> wrote: > Fabian Braennstroem wrote: >> Hi, >> >> I have a 'simple' problem with a multidimension array in a >> for loop. It looks like this: >> >> wert= zeros([127,2]) >> wert1= zeros(127) >> m=1 >> l=1 >> >> for pos in [pos1,pos2,pos3]: >> for i in range(1,125): >> wert[l,m]= >> probe1.GetOutput().GetPointData().GetScalars().GetTuple1(i); >> #wert1[i]= >> probe1.GetOutput().GetPointData().GetScalars().GetTuple1(i); >> m=m+1; >> l=l+1; >> >> It works for the 1D 'wert1'. Does anyone have an idea? > > Oy vey. > > So the first time through, you are setting the second column of wert. Then l > (btw, never, ever use lower-case "l" as a single-letter variable name; it > looks > like "1") gets incremented to 2, which would try to put data into the third > column of wert. However, wert only has two columns. Thanks! I misunderstood the declaration of a multid-dim array; it works now. > > Are you aware that numpy array indices start with 0, not 1? > > You will probably want to ask numpy questions on the numpy-discussion mailing > list: > > http://www.scipy.org/Mailing_Lists I thought a simple for loop-array-declaration question would fit in this group ... it actually help for this simple problem. Thanks! Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: hidden file detection
Lenny G. wrote: > What's the best way to do cross-platform hidden file detection? I want > to do something like weed-out the files that should be 'hidden' from > os.listdir() (which would be files that start with '.' under Unix, > files that have the hidden attribute set on windows, and whatever it is > that makes Mac files hidden). Is there a util or lib that does this > for me? > > Thanks, > Gary > -- http://mail.python.org/mailman/listinfo/python-list
Selecting multiple directories (TKinter)
Hi, I'm currently using tkFileDialog.askdirectory() to select a single directory. I would like to be able to select multiple directories. tkFileDialog.askopenfilenames() seems to do this for files. What can I do in my situation? Are there alternative classes that provide file dialogs better suited for my purpose? Thanks! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Measuring time of a telnet connect
Hi! I want to realize the following: I want to measure the time it takes to build up a telnet connection to a known host (ip/port). I tried to use subprocess.Popen to build the telnet connection and then to catch the "Trying to connect..." and "Connection established" output. But this didn't work - both had always the same timestamp (time.time()) - i think that's due to some buffers. Has anyone an idea how to solve this? Tanks in advance.. -- http://mail.python.org/mailman/listinfo/python-list
Re: Measuring time of a telnet connect
Jack diederich schrieb: Has anyone an idea how to solve this? import time import telnetlib start = time.time() conn = telnetlib.Telnet('localhost', 80) print time.time() - start Perfect! Thank you.. -- http://mail.python.org/mailman/listinfo/python-list
C-API: A beginner's problem
I recently started learning C since I want to be able to write Python extension modules. In fact, there is no need for it, but I simply want to try something new ... I tried to implement the bubblesort algorithm in C and to use it in python; bubblesort.c compiles fine, but whenever I want to import the modul and call the function I get a segmentation fault. This is what the code looks like: static PyObject *py_bubblesort(PyObject *self, PyObject *args) { PyObject *seq = NULL, *item, *newseq = NULL; int seqlen, i; if(!PyArg_ParseTuple(args, "O", &seq)) { return NULL; } seq = PySequence_Fast(seq, "argument must be iterable"); if(!seq) { return NULL; } seqlen = PySequence_Fast_GET_SIZE(seq); int list[seqlen]; for (i = 0; i <= seqlen; i++) { item = PySequence_Fast_GET_ITEM(seq, i); list[i] = item; } bubblesort(list, seqlen); newseq = PyList_New(seqlen); if(!newseq) { return NULL; } for(i = 0; i < seqlen; i++) { PyList_SetItem(newseq, i, list[i]); } return newseq; bubblesort(int list[], int seqlen) is doing the actual job and it is working. What did I do wrong? As I am quite new to C, I probably made many mistakes, so please feel free to correct me. Cheers, Fabian -- http://mail.python.org/mailman/listinfo/python-list