Re: indentation
Amit Jaluf wrote: is it necessary indentation in python ? Try without and report it -- http://mail.python.org/mailman/listinfo/python-list
Re: monitor mouse coordinates in real-time
Jabba Laci wrote: Could you please help me out how to close the application correctly? I think you should put a flag into the code, which the parent might modify it, so it will tell the child process to quit. Then the flag should need to be read periodically to know whether is time to quit. -- http://mail.python.org/mailman/listinfo/python-list
Re: allow line break at operators
Yingjie Lan wrote: #the new way x = 1+2+3+4+ #line continues as it is clearly unfinished 1+2+3+4 Genrally I prefer this way. Of course, the dot operator is also included, which may facilitate method chaining: x = svg.append( 'circle' ). Dot-ended is to tiny thing that might cause oversights. *If* it'll be used as a secondary option I think it doesn't matter, otherwise *if* use as a compulsory writing mode I'd say it is pretty mistake prone. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to solve it?
守株待兔 wrote: from matplotlib.matlab import * maybe you didn't install it http://matplotlib.sourceforge.net/ BTW you haven't mention what version of python you're running. -- http://mail.python.org/mailman/listinfo/python-list
Re: list comprehension to do os.path.split_all ?
Alan Meyer wrote: This is not properly portable to all OS, but you could simply split on the slash character, e.g., pathname.split('/') more portable pathname.split(os.sep) -- http://mail.python.org/mailman/listinfo/python-list
Re: Recommendations for household finance scripting?
markolopa wrote: I would like to find a good system to keep track of my household finance. Do Python programmers have suggestions on that? Do you use Python to help on this task? libreOffice doesn't do it? -- http://mail.python.org/mailman/listinfo/python-list
Re: Tabs -vs- Spaces: Tabs should have won.
Ian Kelly wrote: but if somebody later tries to edit the file using 8-space tabs I came across this and I like to put a note on top of the script to remember to modify it accordingly. -- http://mail.python.org/mailman/listinfo/python-list
Re: why the following python program does not face any concurrency problems without synchronize mechanism?
smith jack wrote: have run this program for many times,and the result is always 5050 You might not need to make it in a multiprocess environment Try it in the python (3) shell tot= 0 for k in range(1,100): ... tot += k ... print(tot) ... And watch the risults. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Finding duplicated photo
Hello, I came across the problem that Gwenview moves the photo from the camera memory by renaming them, but later I forgot which where moved. Then I tought about a small script in python, but I stumbled upon my ignorance on the way to do that. PIL can find similar pictures. I was thinking to reduce the foto into gray scale and resize them to same size, what algorithm should take place? Is PIL able to compare 2 images? -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: Finding duplicated photo
Billy Mays wrote: It worked surprisingly well even with just the 64bit hash it produces. I'd say that comparing 2 images reduced upto 32x32 bit seems too little to find if one of the 2 portrait has a smile referred to the other. I think it's about that mine and your suggestion are similar, but I'd like to scale pictures not less than 256x256 pixel. Also to take a wider case which the comparison involve a rotated image. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem!!
Irmen de Jong wrote: No, I misplaced my crystal ball. I'm waiting mine, brand new in HD :D, with remote control :D :D -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: HOWTO: Parsing email using Python part1
aspineux wrote: Hope this help someone. Yeah I will learn alot and surely applying to my code. Merci Beaucoup -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
How to save a email message?
Hello, I'm trying to gather some mail and save it. I don't get why it isn't saved as expected. == import poplib, socket, sys from configparser import Error as ProtocolError args= sys.argv[1:] # this is fake but is here as example def Pop3_access(*args): '''Accessing a pop server, doing a function and return a result''' func= args[0]; args= args[1:] try: pop= poplib.POP3(srv_info[0]) pop.user(srv_info[1]) pop.pass_(srv_info[2]) except (poplib.error_proto): raise ProtocolError except (socket.timeout,socket.gaierror): try: pop.quit() except NameError: pass # it wasn't started return result= func(pop, args) pop.quit() return result def func(pop, N): ...return pop.retr(N) ... msg= Pop3_access(func, 4) from io import BytesIO as B fp= B() for l in msg[1]: ...fp.write(l) ...fp.write('\n'.encode()) ... 34 1 50 1 63 1 65 1 36 1 52 1 41 1 114 1 45 1 38 1 74 1 56 1 37 1 34 1 28 1 23 1 33 1 56 1 57 1 17 1 44 1 31 1 54 1 30 1 30 1 0 1 31 1 0 1 39 1 0 1 12 1 32 1 49 1 0 1 6 1 64 1 68 1 0 1 from mailbox import mbox as Mbx mbx= Mbx('/tmp/mb', True) mbx.add(fp) 0 mbx.get_message(0) mailbox.mboxMessage object at 0x1704d10 print(mbx.get_message(0)) === The result is an empty message, but the fp.getvalue() shows file-like stream. Am I missing some point? -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: How to save a email message?
Steven D'Aprano wrote: Thank you very much. But if you seek back to the beginning: x.seek(0) 0 x.read() b'hello' Found the matter and *is* working I discover another problem: one message contains also a different encoding, but mostly it is not possible to represent that writing on the normale console output. from mailbox import mbox as Mbx raises eyebrow Do you need to rename mbox? You don't even save a keypress: shift-m b x and m b o x both take 4 keypresses. You stroke a right point :D I could just use its own name The code was not exactly run from the python shell. I was trying to make a *complete* picture from my module. In fact there aren't the arguments to access the pop server. I'd like to mention that I've looked into the output file, which shows only From MAILER DEAMON + date of the action, but no message at all. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: Emails backup in python 3.2
Michael Hrivnak wrote: Do you have a special reason for wanting to implement your own email storage? Learning python :) It seems very easy to get my mails with the poplib help. Usually I work with Kmail which imports mbox files. I'm not prone to set up a SMTP server on my PC. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: How to iterate on a changing dictionary
Terry Reedy wrote: Other situations will need other solutions. Like a job's completion list. Some number of workers get a job, and by time the caller sould know who and what has finished. Then a dictionary would hold number of remaining jobs. Similar a downloading list. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Emails backup in python 3.2
Hello, I'm looking for an idea how to backup emails retrieved by poplib and save them into mailbox.mbox file. The problem is the received message which is a list of bytes streams, mailbox.mbox don't expect a list. What conversion should I do? A file type io.StringIO ? decoding every bytes stream which might not have any declared codec? As far as python moved into unicode, why doesn't it handle these undecoded bytes as it was with strings before? -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: How to iterate on a changing dictionary
Lie Ryan wrote: Thank you all for the information, really apreciated. While there are legitimate reasons for iterating a dictionary, I'd consider the alternatives first. Perhaps the correct answer is in what you said. For certain reasons, searching in a dictionary is the fastest method, secondly the positions of the data aren't relevant and easy to find. My primer purpose is to know how much of work is done as soon the child process reports completion of a part. The order of the given jobs are not linear as it could do with a list. To make an example: imaging Bingo.Shuffle the numbers, each number sorted should be removed from the container, how would it implemented? -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
How to iterate on a changing dictionary
Hello Trying to pop some key from a dict while is iterating over it will cause an exception. How I can remove items when the search result is true. Example: while len(dict): for key in dict.keys(): if dict[key] is not my_result: dict.pop(key) else: condition_to_break print('Dictionary is over') this is my mistake, but where to fix? -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: What would you like to see in a File Organizer ?
zainul franciscus wrote: we are looking for some ideas for good functionality for the application. T I was looking for a file cataloger. this program may go into same category as far as handling file names ad file system's structures. It also manage to store unused files into zipped archives and recall them transparently once the system is looking for it. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: What's the best way to write this base class?
John Salerno wrote: class Character: I'd vote to point 1 -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: Composing regex from a list
Steven D'Aprano wrote: def compile_alternatives(*args): Thank you all, for these good points. For my eyes seem that explicit or implicit it will take some looping to concatenate the list elements into a string. I will see pypy later. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: Function within class and in modules
Zach Dziura wrote: Just repeat this to yourself: Python ISN'T Java I never had to do anything in Java. But mostly something in Sumatra :D I'm getting the point that I'll need class very seldom. Only to understand some more the use of self, whether I'll use a class. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Composing regex from a list
Hello, Is it possible to compile a regex by supplying a list? lst= ['good', 'brilliant'. 'solid'] re.compile(r'^'(any_of_lst)) without to go into a *for* cicle? -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Function within class and in modules
Hello sorry, I'm bit curious to understand what could be the difference to pack up a class for some number of functions in it and a simple module which I just import and use the similar functions? The only perspective that I think of is that class might instantiate a function several time. For my use I don't have multithread and mostly programs are sequencial. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: Deditor 0.3.0
Kruptein wrote: Deditor is a text-editor for python developers, I'd like a editor that runs programs on trace and highlight the line(s) where it step into. Obviously, if running at normale speed it will disable or if the speed is reduced it will works. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Handling emails
Hello I wrote a program which was working on python 2.x. I'd like to go for newer version but I face the problem on how the emails are parsed. In particular I'd like to extract the significant parts of the headers, but the query to the servers had turned in to list of bytes. What could be a method that will parse and return the headers into ascii if I'll pass the headers as bytes. Even I don't know whether I can pass as they arrive to the program. For example if I try: import poplib.POP3 _pop= poplib.POP3(srvr) _pop.user(args[1]) _pop.pass_(args[2]) header =_pop.top(nmuid, 0) This will return a list of bytes string and I don't have idea to process them in order to have a dictionary containing 'from', 'to', 'cc', 'bcc', 'date', 'subject', 'reply-to', 'message-id' as keys. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: Handling emails
Steven D'Aprano wrote: First of all: thanks for the reply header =_pop.top(nmuid, 0) To parse emails, you should use the email package. It already handles bytes and strings. I've read several information this afternoon, mostly are leading to errors. That could be my ignorance fault :) For what I could come over, I decided to write my own code. def msg_parser(listOfBytes): header={} for lin in listOfBytes: try: line= lin.decode() except UnicodeDecodeError: continue for key in _FULLhdr: if key in line: header[key]= line continue return header listOfBytes is the header content, whuch id given by libpop.POP3.top(num_msg. how_much), tuple second part. However, some line will fail to decode correctly. I can't imagine why emails don't comply to a standard. Other than that, I'm not entirely sure I understand your problem. In general, if you have some bytes, you can decode it into a string by hand: I see. I didn't learn a good english yet :P. I'm Italian :) header = b'To: python-list@python.org\n' s = header.decode('ascii') s 'To: python-list@python.org\n' I know this, in case to post the entire massege header and envelope it's not applicable. The libraries handling emails and their headers seems to me a big confusion and I suppose I should take a different smaller approach. I'll try to show a header (if content isn't privacy breaker) but as the above example the *_pop.top(nmuid, 0)* won't go into your example If this is not what you mean, perhaps you should give an example of what header looks like The difference is that previous version returning text strings and the following processes are based on strings manipulations. Just to mention, my program reads headers from POP3 or IMAP4 server and apply some regex filtering in order to remove unwanted emails from the server. All the filters treating IO as ascii string of characters. I passed my modules to 2to3 for the conversion to the newer python, but at the first run it told that downloaded header is not a string. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: (*args **kwargs) how do I use' em?
OliDa wrote: maybe some clarification about kwargs... http://stackoverflow.com/questions/1098549/proper-way-to-use-kwargs-in- python Great point. Now it's clearer :) I think I'll share the dictionary which contains the configuration loaded form a file. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
(*args **kwargs) how do I use' em?
Hello, I'm seldomly writng python code, nothing but a beginner code. I wrote these lines = _log_in= mhandler.ConnectHandler(lmbox, _logger, accs) multhr= sttng['multithread'] if multhr: _log_in= mhandler.mThreadSession(lmbox, _logger, accs) for svr in servrs: nmsvr, user, pwd, ptcl = servrs[svr] al, dn= sttng['Cfilter']; er= sttng['filter'] try: rx.append( _log_in.connect((nmsvr, user, pwd, ptcl, (al, dn, er except ProtocolError: print(svr+ errors['SerProb']) except KeyboardInterrupt: raise SystemExit(errors['YouStop']) if multhr: for s in rx: try: s.start() except (ProtocolError, AttributeError): print(svr+ errors['SerProb']) except KeyboardInterrupt: raise SystemExit(errors['YouStop']) for s in rx: try: s.join() # waiting all threads to finish except (ProtocolError, AttributeError): print(svr+ errors['SerProb']) except KeyboardInterrupt: raise SystemExit(errors['YouStop']) = Surely ugly and I believe that would be a better way to pass the arguments as I mention on the subject. Then it should give a dictionary of keywords and some function or a callable. I don't know how to put down these code lines. I think I should restructure many points of my data. Any suggestion will make me happier :) -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: The pythonic way equal to whoami
Christopher Head wrote: It is. Until Linux capabilities, EUID==0 used to be special-cased in the kernel Thank you all, I got a good learning *and* something to rememeber. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Iterating into maildir or mbox
Hello, originally with python 2.4 ~ 2.7 (I think) iterating a maildir I was using ++Code+ try: mbox= mailbox.PortableUnixMailbox(open(mbox,'r')) except IOError: # if file not found default is None mbox= None while mbox: msg= next(mbox) if msg is None: break try: m= msg.getheader('message-id') if m: dx= m.strip('') else: continue except (IndexError, AttributeError, IOError): # message without ID, put some mark dx= str(time.time()).split('.') dx= int(dx[0])*int(dx[1]) if dx in lmbox:continue lmbox[dx]= dx return lmbox ++Code+ I'm tryng to convert into Python 3.2, but I don't get why this is not iterable anymore. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: The pythonic way equal to whoami
Kushal Kumaran wrote: os.geteuid This return 0 for *root* . I don't know if it's a standard for all distro. Mine is Archlinux. I'd just like to avoid error caused by wrong access by user -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: A simple way to print few line stuck to the same position
Hans Mulder wrote: If you use curses, you must initialize it by calling curses.initscr(), which returns a WindowObject representing the konsole window. To put things on the screen, you call methods on this object. Keep in mind that a window in curses jargon is just a rectangle inside your konsole window I've learned great things from you. Thank you very much. The curse window I could realize it immediately that it's a part of console screen, in curses module. Usually it's represented as blue box with some shadow effect :) Deleting old writing it's another good point. Actually, I reduced in a simplier solution with one line report :P. I'll look into curses for some better visual effects. Playing with tabs (vertical and horizontal) I think it won't be a reliable method, unless when the position it would stick to the upper left corner of the console. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
The pythonic way equal to whoami
Hello, I was trying to find out whose the program launcher, but os.environ['USER'] returns the user whom owns the desktop environment, regardless the program is called by root. I'd like to know it, so the program will run with the right privileges. Is there any standard function on python, that will do it? -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: A simple way to print few line stuck to the same position
Hans Mulder wrote: A minimalist solution would be to print the labels (This count, etc.) only once, and position the cursor after it to update the report. Generally a good point. Similar sequences are working for coloring and formatting text. I don't know whether the program would behave to someone else who using not konsole like I do. The module is called curses and, yes, it would be the best way to go. OK, I didn't understand if I must setup a window first in order to implement cursor positioning. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: A simple way to print few line stuck to the same position
Steven D'Aprano wrote: def spinner(): chars = '|/-\\' Not exactly. I'd like to show 4~6 line of report and refreshing periodically all of them, avoiding to scroll down. example: this count 50 Second time 90 following line 110 another line xxx The lines should remain on their position and update their data. I think, I should go for course module, but it's a bit of learning, which I didn't embarked yet. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
A simple way to print few line stuck to the same position
Hello I studying some way to print few line in the console that won't scroll down. If was for a single line I've some idea, but several line it may take some vertical tab and find the original first position. I don't know anything about course module, some example will be highly apreciated. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: How to catch a line with Popen
Chris Torek wrote: Since it is a generator that only requests another line when called, it should be fine Is it, then, that until the new itaration, the callee is on pause? -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: How to catch a line with Popen
Chris Torek wrote: In at least some versions of Python 2 I'm with P3k :P. However thank you for your guidelines. Last my attempt was to use a *for* p.wait() , as mentioned earlier That looks good enough. I noted some little delay for the first lines, mostly sure Popen assign some buffer even it is not set. Haven't you try a perpetual ping, how would be the line_at_a_time ? -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: How to catch a line with Popen
Tim Roberts wrote: Are you specifying a buffer size in the Popen command? If not, then the Python side of things is unbuffered The buffer is as per default. The program reports one line around 1/2 second time. I think I'll look into the option as Nobody states: p = subprocess.Popen(...) for line in p.stdout: ... p.wait() It is strange that would take a for cycle, rather than catching the line on- the-fly. I can judge it now, I'm going to try it out. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: How to catch a line with Popen
Chris Rebert wrote: What do you mean by on-the-fly in this context I just suppose to elaborate the latest line, as soon it's written on the pipe, and print some result on the screen. Imaging something like p= Popen(['ping','-c40','www.google.com'], stdout=PIPE) for line in p.stdout: print(str(line).split()[7]) I'd like to see something like *time=54.4* This is just an example, where if we remove the -c40 on the command line, I'd expect to read the latest line(s), until the program will be killed. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: How to catch a line with Popen
TheSaint wrote: I just suppose to elaborate the latest line, as soon it's written on the pipe, and print some result on the screen. I think some info is also here: http://alexandredeverteuil.blogspot.com/ -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
How to catch a line with Popen
Hello. I'm looking into subprocess.Popen docs. I've launch the program with its arguments and that's smooth. I'm expecting to read the output by *comunicate()* at every line that prgram may blow during the process, but the output is given only when the child process is ended. I'd like to process the lines to display an information in percentage during the running time of the child. Sorry but I'm poor of know-how, so I'm stuck over to find a clue. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get PID from subprocess library
Anssi Saari wrote: Couldn't you just try to call something via this handle, like self.handle.aria2.getVersion()? If there's an error, then start aria2 as a daemon and try again. Very good, you're right. Furthermore I should avoid to call that function several times. I think to join it with __init__ function The program on exit must tell aria2c to quit. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get PID from subprocess library
GMail Felipe wrote: For the ps command, have you seen the psuti module? The link to it is: http://code.google.com/p/psutil/ You gave a brand new start :) I bit of additional program to include into the package ;) -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get PID from subprocess library
Kushal Kumaran wrote: You could look for a way to make aria2c not become a daemon and use subprocess.Popen to start it. That gives you the PID and ways to see if the process is still running I see. It's a step that I've to get on my account. Unfortunately I'll have to study it some more. BTW. I removed grep from the command. Python does it with the *in* statement :) -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get PID from subprocess library
Kushal Kumaran wrote: That's how it is able to give you the status. So, if you are using getstatusoutput, you will have only one instance of your command running. My intent is to launch only one program instance, which will goes as daemon. To avoid a second call I'd like rather to use Python than ==code= def start(self): '''try to start aria2c as a daemon and return its handle to where it can proceed to issue commands''' # aria2c is running, then don't try it again if (chkout('ps -A |grep aria2c')[0] 0): try: chkout(self.ARIA_CMD) except: raise SystemExit('aria2c is not working as deamon') elif self.handle: return self.handle # everything is good, it will return an handle self.handle= \ xmlrpclib.ServerProxy('http://localhost:%s/rpc' %int(self.numport)) return self.handle ==code= Here I've named subprocess.getstatusoutput as chkout, I'm calling 2 more programs to find whether there's a running instance of aria2c. I think it's not nice, python libraries should get the matter done. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get PID from subprocess library
Miki Tebeka wrote: The best module for doing such things is subprocess. And the Popen object has a pid attribute I knew that, it's my fault that I'm not good to manage with popen. I found simplier to use subprocess.getstatusoutput. Maybe this function doesn't return the child pid, so I should adopt to work with Popen :( -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
how to get PID from subprocess library
hello, I'm using to launch a program by subprocess.getstatusoutput. I'd like to know whether I can get the program ID, in order to avoid another launch. For clarity sake, I'm calling aria2 (the download manager for linux) and I wouldn't like to call one more instance of it. So what will I use to find the PID of the launched program? -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting a set into list
Thomas Rachel wrote: Which loops do you mean here? list(set) has been proved to largely win against list = [] for item in set: list.append(item) or [list.append(item) for item in set] -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting a set into list
SigmundV wrote: I think the OP wants to find the intersection of two lists. list(set(list1) set(list2)) is indeed one way to achieve this. [i for i in list1 if i in list2] is another one Exactly. I was confused on that I wasn't able to have a list in return. The set intersection is the smartest result better than a for loop or a comprehension list. Infact the operatin loops are compiled into python, therfore they are the fastest. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting a set into list
Chris Torek wrote: x = ['three', 'one', 'four', 'one', 'five'] x ['three', 'one', 'four', 'one', 'five'] list(set(x)) ['four', 'five', 'three', 'one'] Why one *one* has purged out? Removing double occurences in a list? -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting a set into list
Steven D'Aprano wrote: s = set() s.add(42) s.add(42) s.add(42) print s set([42]) Good to know. I'll remember it -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: how to install easy_install
rusi wrote: tried to install easy_install (This is on windows) I downloaded the executable and ran it. It claimed to have done its job. Perhaps, the abit to just click is disordering some easy steps like copy the script files into the normal place. Only when there's a particular copy then it's the time to pay attention, like some executable and/or framework. In the README.txt should mention these few easy steps -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Converting a set into list
Hello I've stumble to find a solution to get a list from a set code aa= ['a','b','c','f'] aa ['a', 'b', 'c', 'f'] set(aa) {'a', 'c', 'b', 'f'} [k for k in aa] ['a', 'b', 'c', 'f'] /code I repute the comprehension list too expensive, is there another method? -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting a set into list
Peter Otten wrote: mylist = list(myset) Do you notice the similarity to converting a list to a set? There was something confusing me yesterday in doing that, but (for me strangely) I got cleared out. The point was that after a result from: newset= set(myset1) set(myset2) list= [newset] [{'bla', 'alb', 'lab'}] Probably list(set) is not like [set]. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting a set into list
Ben Finney wrote: Another method to do what? Sorry, some time we expect to have said it as we thought it. The example was to show that after having made a set set(aa) the need to get that set converted into a list. My knowledge drove me to use a comprehension list as a converter. In another post I got to know the simplest way to state list(aa) Where aa is a set. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Trace in a class
Hello, first of all, I'm a dummy in programming. My methods are just do-it-and-try- it. For more convinience I commonly using pdb myprogram and go with step-into and breakpoints. Lately I was setting a class, but it's incomplete and just calling it at the pdb prompt line I can't use breakpoints or stop it to check what values are coming into the play. BTW, would it be much difference to use the class functions outside the class. I mean I don't declare the class statement just leave funtions alone in the module. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: unicode by default
John Machin wrote: On Thu, May 12, 2011 2:14 pm, Benjamin Kaplan wrote: If the file you're writing to doesn't specify an encoding, Python will default to locale.getdefaultencoding(), No such attribute. Perhaps you mean locale.getpreferredencoding() what about sys.getfilesystemencoding() In the event to distribuite a program how to guess which encoding will the user has? -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Py3k,email header handling
Hello, some time ago, I wrote a program to eliminate undesided emails from the server(s) and leave those which comply to certain filter criteria. I started it when I got to know whit Python 2.3. Now a days I'd like to spend some time to improve it, just for my interest, however it didn't gather anybody's interest before. Now python 3.2 (and some version before) started to use byte, rather than text strings, almost for all data handling in compliance to unicode. My problem arise that my program handle text strings, so I'd like to rewrite the code My program reads from IMAP4 or POP3 server, I'd prefer that a function/class will return either a list or a dictionary which contains the following fields: 'from', 'to', 'cc', 'bcc', 'date', 'subject', 'reply-to', 'message-id' The list may be organized as tuple (from, its_content,), etc,etc for each field, but I think dictionary would be more efficient to use. 1) is there a way to call the IMAPlib or POPlib and pass the data directly to email.parser.HeaderParser to achieve my intention? 2) If the above will do, do re.compile compile unicode results? I guess yes. 3) any related documentation... -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: Py3k,email header handling
Steven D'Aprano wrote: Before you re-write it, you should run 2to3 over it and see how much it can do automatically: Widely done, only the results from some query has radically changed on favour of unicode. Errors raising about results which are not strings anymore. I'm afraid I don't understand the question. Making an example : from poplib import POP3 as pop3 pop3.user('userid') pop3.pass_('password') numMsg, total = pop3.stat() for cnt in numMsgs: header = pop3.top(cnt) # here I'd like to pass the header to some function that will return # a dictionary filling # from', 'to', 'cc', 'bcc', 'date', 'subject', 'reply-to', 'message-id' # keys, if nothing the leave empty string or None dict = email.header,decode_header(header) # but might not my result # Should I subclass this? The same would be from the IMAP4 message parsing. Some different process would take, would it ? If you have any more concrete questions, please ask. If these aren't concrete questions, forgive me, I perhaps got into wrong news group. In the other and I hugely apreciated your clues. I'll see the docs some more long to achieve a clear learning. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: A suggestion for an easy logger
Vinay Sajip wrote: No, you can pass keyword arguments in any order - that's what makes them keyword, as opposed to positional, arguments. I getting puzzled :) ==code== myself@laptop-~ python Python 3.2 (r32:88445, Apr 15 2011, 11:09:05) [GCC 4.5.2 20110127 (prerelease)] on linux2 Type help, copyright, credits or license for more information. import logging, sys logging.basicConfig(level=logging.DEBUG, format='%(message)s') sh = logging.StreamHandler(sys.stdout) sh.terminator = '' logging.getLogger().addHandler(sh) logging.debug('here we are') here we are here we are print(logging.__version__) 0.5.1.2 ==code== Terminator is removed, but as you stated it's doing double print-out One more point is, if you'd have the time to look back to one of the first posts, that the leading *DEBUG:root:* doesn't show :-/ It's reported herein the version of Python and logging module's version. For my thinking I'd go to look into the code and docs as well, to understand what I should do to have my 4 way of logging. I repeat, I'm very new on using logging module, but I should go in that way, it isn't necessary to re-invent the wheel :). Also I'd like to say that's only for my own learning, which I do as hobby. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: A suggestion for an easy logger
Vinay Sajip wrote: logging.basicConfig(level=logging.DEBUG, format='%(message)s') logging.basicConfig(format='%(message)s', level=logging.DEBUG) I formulated in the reverse order of arguments, may that cause an unpredicted result? The other points became clearer.. Once again Thank You -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: A suggestion for an easy logger
TheSaint wrote: I'd like to just have the 4 conditions mentioned in the first post. OK, my analysis led me to the print() function, which would suffice for initial my purposes. Meanwhile I reading the tutorials, but I couldn't get how to make a formatter to suppress or keep the LF(CR) at the end of the statement. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: A suggestion for an easy logger
Vinay Sajip wrote: 8 For Python 3.2 and later, it's the terminator attribute of the StreamHandler. See: 8 Unfortunately, for earlier Python versions, you'd need to subclass and override StreamHandler.emit() to get equivalent functionality :-( I'm with 3.2 and willing to stay :) I was trying ==code== logging.basicConfig(format='%(message)s',terminator='',level=logging.DEBUG) logging.debug('here we are') DEBUG:root:here we are ==code== First I didn't espect to see much more than my message. I agree that I'm very new to the module Second the will terminator appear only to real stdout, or am I doing something incorrect? Note: some word wrapping doesn't show the python shell correctly. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
A suggestion for an easy logger
Hello, I've resumed my hold project and I like to convert it for py3k2. My knowledge has stagnated at version 2.4, then I found some improvements, but it will take me some time before I get used to. I was using this logger = class log: It outputs lists and strings on file or any possible device that allows write mode. Options are: output file writing mode and special end of line (EOL) def __init__(self, output= None, mode= 'w', lsp= EOL): Can instantiate even no output is given. Choose to build an open file object to append to, or new and give a different line separator self.lsp = lsp self.output= output self.mode= mode try: self.output= open(output, self.mode) except (IOError, TypeError): self.output = None def logger(self, strng, allowed=None): # without any output will simply send log to nowhere :-) if not allowed and not self.output: return # no allowed to write the output # keep silent even temporary skip writing # if allowed, it will go to stderr if isinstance(strng,list): a= EOL.join(strng)+ EOL strng = a strng= strng.replace(EOL,self.lsp) # when not allowed just return if allowed is None: return if strng == '?close?': try: # try to close the file self.output.close() return except IOError: return # silently ignore the failure if self.output and Exists(self.output): self.output.write(strng) else: sys.stderr.write(strng) sys.stderr.flush() return = It is somehow convulitive, isn't it? I do believe the builtin *print* would do more better than my logger. Basically I would like a class which shoudl do: 1) print to stdout either with or without carriage return 2) writing to a file 3) Skip some output Everything should do according to the caller. I didn't picked up the logging module, a way of confusion on my point of view. Some small example might easy my aberration :P -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
Gregory Ewing wrote: because modern architectures are so freaking complicated that it takes a computer to figure out the best instruction sequence certainly is, I would not imagine one who writes on scraps of paper :D :D :D -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: A suggestion for an easy logger
Vinay Sajip wrote: WoW :O , the creator !! import logging logging.basicConfig(level=logging.DEBUG) I'm getting there, but the result it's not what I would. As far as I got to know, it should take to write a configuration file, which I still not aware of. I'd like to just have the 4 conditions mentioned in the first post. Once I'll get into the dirt I'll try to bring up also the other features that logging module gives. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: marshal.dumps quadratic growth and marshal.dump not allowing file-like objects
On 16:04, domenica 15 giugno 2008 [EMAIL PROTECTED] wrote: cStringIO.StringIO object to marshal.dump() instead but I quickly learned this is not supported (only true file objects are supported). Any ideas about how to get around the marshal quadratic issue? Any hope for a fix for that on the horizon? If you zip the cStringIO.StringIO object, would it be possible? -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Hard to understand 'eval'
On 04:08, domenica 15 giugno 2008 [EMAIL PROTECTED] wrote: what's wrong with getattr(cp, nn) ? The learning curve to get into these programming ways. Does gettattr run the snippet passed in? Considering that nn is a name of function, which will be called and (cfl, value) are the parameters to passed to that function. I'll spend some bit on getattr use. -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Hard to understand 'eval'
On 06:34, domenica 15 giugno 2008 Dennis Lee Bieber wrote: for nn in stn_items: I already see a syntax error when viewing that in Agent... A missing indent level under the for The program don't complain wrong indentation, I mostly sure a wrong copy-paste error. Error doesn't come up there. . You also don't need the continue if you change the second if into elif. My mistake, I thought that was improving the loop. is it an ifelifelif probing only the first matching case and drop the remaining checks? And what type of structure is cfl? You got close, that's a dictionary of dictionaries and I'm trying to updating it. wonder what this mysterious _append() function is supposed to be doing; Append() is a conventional name regarding a file logging. There would be an option to set a quota of bytes size. Huh... I presume you mean to convert from a text decimal it isn't so, the function look at the string to see if ending by K or M, which means Kbytes or Mbytes. It'll return the decimal conversion. If the value is set as boolean value, then it will do appending to the log when it True or stop appending when there's a quota. def _append(c, v): RE_BYTE= re.compile(r'^[\d]+(k|m)?$',re.I) # any number of digit followed by 0 or 1 (k or m), case insensitive chkbool(v) if isinstance(v,bool): c['append']= v return c if RE_BYTE.match(value): k= 1024; M= k * k; v= int(value[:-1]) if value[-1:] == 'k': v= v * k if value[-1:] == 'm': v= v * m c['append']= v return c All the code could be download at my web site ;) But this here it's a bit new concept. -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Configuration files
On 04:11, domenica 15 giugno 2008 Daniel Fetchinson wrote: Check this out: http://www.voidspace.org.uk/python/configobj.html Let me add: cfgparse, iniparse I've look at all to find a simple solution for my interest, but I realized not a good result. I'm using three of them ConfigParser, cfgparse and optparse. Just to let read a configuration file and let user to subclass option at the console. If I'll get experienced by cfgparse I think I'll drop ConfigParser, because I'd like the idea to override file rules on console. -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Hard to understand 'eval'
On 01:15, lunedì 16 giugno 2008 Calvin Spealman wrote: such as getattr(obj, methname)(a, b, c). Does this make sense? This is big enlightenment :) Thank you! :) I found problem with eval() when it comes to pass quoted strings. I circumvent that by encapsulating the strings in variable or tuple. The principle is to have a name which will refers a function somewhere in the program and to call that function, plus additional data passed in. In other word I'd expect something: function_list= ['add' ,'paint', 'read'] for func in function_list: func(*data) I tried getattr, and I saw that result. I only investigate a little, so I still have a small perplexity. -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Hard to understand 'eval'
On 05:05, 16-6- 2008 Dennis Lee Bieber wrote: # any number of digit followed by 0 or 1 (k or m), case insensitive I don't do regular expressions... and the comment doesn't help digit followed by 0 or 1, when 0/1 ARE digits themselves... That means either none or one letter, of which k or m are allowed. c is a mutable object; you don't have to return it; the change is seen by anything holding a reference to the object. C is a dictionary, it might be omitted, but I'm still not sure if will lose its state. Again, as c is mutable, it doesn't need to be returned. Apparently Not so apparent, it's doing that, buddy :) v = v.strip().lower() regexp did a fine check and case insensitive, but I like your idea too. Biggest flaw, in my mind... You are using ONE identifier to control TWO meanings... a boolean On/Off control AND an integer size limit control. That occupy only small variable and as long as python can accept anything not zero, false or none for an _if_ condition, that might be allowable, I think. Then if not zero will mean the log will be *appended* to an existing file and if the value is something that can be converted in decimal value, then this will set the quota for the log file, as well. Here below dbg is the log file and if it isn't None then s a valid file path should work. dbg= sttng['log']; mode= 'w' # normally write, it writes new try: if sttng['append'] Path.getsize(dbg): mode= 'a' except (OSError, TypeError): # found a boolean or dbg is new file pass So 5 line of code can do me the job smartly, I think ;) -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie question: for loop within for loop confusion
On 09:23, lunedì 16 giugno 2008 takayuki wrote: word = line.strip() Try word= line.split() and at the end of the loop add one more print to go to new line. -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
Hard to understand 'eval'
Hi, It seems to be strange that give me syntax error inside an eval statement. I'm looking at it carefully but I can't see any flaw. Here it's part of the code: for nn in stn_items: value= eval('cp.%s' %nn) if value and (nn in 'log, trash, multithread, verbose, download'): cfl[wchkey][nn]= chkbool(value) continue if value: cnfg= 'cfl[wchkey][nn]= _%s(value)' %nn eval(cnfg) And the output on pdb: (Pdb) p cnfg 'cfl[wchkey][nn]=_append(value)' (Pdb) p cfl[wchkey][nn] False (Pdb) eval('cfl[wchkey][nn]= _append(value)') *** SyntaxError: invalid syntax (string, line 1) (Pdb) p value '230k' (Pdb) p nn 'append' Obviously I've an _append() function to convert into decimal the given value. Other eval before this not issuing problems and also rather complicated, but I'm not seeing the error here. I'd like to study a class that might get a string and convert it into function, once it's found inside the program. -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: can't assign to literal
On 17:06, venerdì 13 giugno 2008 Dennis Lee Bieber wrote: -=-=-=-=-=-=- (make sure you have a fixed width client) Very good indeed :) Specially to do with block reformatting. I just post my script to demonstrate my thoughts in what I meant as justifying. Specially considering that I meant character justification regardless of its width. Monospace chars will show pretty alignment. BTW, I'm beginner and my coding takes much try-and-test. ;) -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Checking list by using of exception
On 15:37, venerdì 13 giugno 2008 Nader wrote: try: list_of_files != [] get the files For file in list_of_files: try: myfile = open(file, 'r') except (IOError, OSError): printYour %s file wasn't open %file # here you can do something with your open file as read option myfile.readlines() # for example -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Debuggers
On 19:21, venerdì 13 giugno 2008 R. Bernstein wrote: I'm not completely sure what you mean, but I gather that in post-mortem debugging you'd like to inspect local variables defined at the place of error. Yes, exactly. This can be seen with pdb, but not pydb. If I'm testing a piece of code and it breaks, then I'd like to see the variables and find which of them doesn't go as expected. Python as a language is a little different than say Ruby. In Python the handler for the exception is called *after* the stack is unwound I'm not doing comparison with other languages. I'm simply curious to know why pydb don't keep variables like pdb. Final, I agreed the idea to restart the debugger when an exception is trow. It could be feasible to let reload the file and restart. Some time I can re-run the program , as the error is fixed, but sometime pdb doesn't recognize the corrections applied. I mean that after a post-mortem event, the debugger should forget all variables and reload the program, which meanwhile could be debugged. -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: write Python dict (mb with unicode) to a file
On 17:13, sabato 14 giugno 2008 dmitrey wrote: hi all, what's the best way to write Python dictionary to a file? Pickle or ConfigParser. You may gather more details at http://docs.python.org/lib/persistence.html -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: can't assign to literal
On 15:11, giovedì 12 giugno 2008 Dennis Lee Bieber wrote: Word spaced line justification is only feasible if one is using a fixed width font and have a line length defined in characters/line. ===8==8==8==8==8==8==8==8==8==8 line= 'fixed width font and have a line length defined in characters/line.' lenLine= 78; newLine= ''; Words= line.split(' ') lnWords= len(Words); norm_spc= lnWords-1; xtr_spc = lenLine -len(line) lenChr= len(line)-norm_spc numspc= (norm_spc+ xtr_spc)/ norm_spc lstword= len(Words[norm_spc]) for spc in range(lnWords): if len(newLine)+lstword + numspc lenLine : break newLine += Words[spc]+(' '* numspc) if xtr_spc: newLine += ' '; xtr_spc -= 1 print newLine+ ' '+ Words[spc] ===8==8==8==8==8==8==8==8==8==8 In my mind it took me just few seconds :), but to get it working I spent nearly *one* hour. I admit that my skill lacks of knowledge ]) -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
My editing style (was: can't assign to literal)
On 14:49, giovedì 12 giugno 2008 Chris wrote: You should strip all extraneous white space from code though. For my taste, trailing spaces will be removed by my editor (Kate :) ) Other space tabulators are an issue which won't suite my needs. -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
Debuggers
Hi, while testing my program I found some strange happening with pdb and pydb. I like pydb because let me restart the program and nicer features, but if errors pop up, then it will forget all variables (globals and locals gone). I've to go for pdb because it isn't affected by that problem, but also in some case pdb doesn't recognize a fix after a post-mortem restart. The funny thing is that it shows the line corrected, but pdb execute the one it put in memory. However, I think also python shell has such flaw. I'd like to know how to blank all current data and restart a program or re-import a corrected class sentence. Any other to try? I'm also prone to use Ipython, but I still miss some learning how to run a program within Ipython itself. So if I do: import myprogram myprogram.__main__ Will it run? And then the other arguments from CLI, how do I pass them in? -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: can't assign to literal
On 01:37, giovedì 12 giugno 2008 Ethan Furman wrote: Do you mean indenting, or wrapping? I mean fill the line by increasing spaces between words in order to get a paragraph aligned both side, left and right on the page. So if the width is 78 chars it wouldn't have jig saw end to the right side, unless applying some word hyphenation. This feature would be nice for writing here and some plain documentation plain text. Beside that it might doing for Python scripts as well. -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: My fight with classes :)
On 04:51, giovedì 12 giugno 2008 Terry Reedy wrote: First of all a big thank you, all. def makeappender(): data = ['',''] def appender(val): code that mutates data return appender I'll give it a try. I just doubting if the data will be shared outside the function. Actually, my practice goes to send all variables to the functions and expecting a returned value. Usually I'm not relying on that module's variables are read inside a function. Probably I got wrong learning or experiences. For multiple functions, use classes. That's what I'm leaning to :) Then I re-elaborated the class according your points and now it's what I wanted to be. :) (last time I forgot to past the first line) Here it comes: class StrJoin: Join a pair of strings according to the leading first letter A or D, it returns a list of 2 elements def __init__(self): self.valueA= '' self.valueD= '' def append(self, value): if not isinstance(value, str): raise TypeError, 'Wrong type concatenation' if value.lower().startswith('a'): self.valueA += value if value.lower().startswith('d'): self.valueD += value return [self.valueA ,self.valueD] def __getitem__(self,idx): if idx 1 : return self if idx == 0 : return self.valueA if idx == 1 : return self.valueD __call__= append def __repr__(self): return '['+ self.valueA+ ','+ self.valueD+ ']' And the shell : from utilities import StrJoin as zx k = zx() k [,] k('add') ['add', ''] k[2] [add,] k[1] '' k[0] 'add' k('dad') ['add', 'dad'] k('sad') ['add', 'dad'] k('Alfa') ['addAlfa', 'dad'] k('Dude') ['addAlfa', 'dadDude'] k('Omega') ['addAlfa', 'dadDude'] k('Dome') ['addAlfa', 'dadDudeDome'] k.append[k] Traceback (most recent call last): File stdin, line 1, in module TypeError: 'instancemethod' object is unsubscriptable k(89) Traceback (most recent call last): File stdin, line 1, in module File utilities.py, line 33, in append raise TypeError, 'Wrong type concatenation' TypeError: Wrong type concatenation Mostly I'll use the call option. I also like to pass it into a function in order to modularize the loop where it gets started. -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: My fight with classes :)
On 17:47, giovedì 12 giugno 2008 Bruno Desthuilliers wrote: For multiple functions, use classes. Well... Closures are poor men's objects, or so they say (or is that the other way round ?-). Well, I'd like to know what could be the reason to design a single-call class instead of a similar function. def make_person(name, age): state = dict(name=name, age=age) def set_name(new_name=None): I'm going to get a deeper thinking about a function's function :) -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
My fight with classes :)
Hi, I'm very new with classes. I still reading something around ;) I got started to try a concatenation of 2 type of string, which have a particular property to start with A or D. My class here: Small class to join some strings according to the leading first letter def __init__(self): self.valueA= '' self.valueD= '' def __add__(self, value): if not isinstance(value, str): return if value.lower().startswith('a'): self.valueA += value if value.lower().startswith('d'): self.valueD += value return self.valueA ,self.valueD __call__= __add__ __iadd__= __add__ my test on the shell: from utilities import StrJoin as zx k= zx() k utilities.StrJoin instance at 0x9dc7ccc k +'aks' ('aks', '') k +'daks' ('aks', 'daks') k +'hdaks' ('aks', 'daks') k +'dhks' ('aks', 'daksdhks') j('boi') Traceback (most recent call last): File stdin, line 1, in module NameError: name 'j' is not defined k('boi') ('aks', 'daksdhks') k('aboi') ('aksaboi', 'daksdhks') k('duboi') ('aksaboi', 'daksdhksduboi') k += 'liu' k += 'aliu' Traceback (most recent call last): File stdin, line 1, in module TypeError: can only concatenate tuple (not str) to tuple k ('aksaboi', 'daksdhksduboi') Do I miss something? I'd rather like to avoid class, but a function won't allow me to store so easily data between several call. Mostly I'd expect to pass to the built instance in a more elaborated function. Then I mean call will be the primer goal. -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: can't assign to literal
On 16:47, mercoledì 11 giugno 2008 Chris wrote: SciTE and Notepad++ Pype, spe, just to point it out. Jedit, but rather a bloatware. I'd like to know which is the litest multi platform and indipendent. Pype is very good when compiled in exe, but not doing in Linux in that way. -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: catastrophic regexp, help!
On 12:20, mercoledì 11 giugno 2008 cirfu wrote: patzln = re.compile((\w* *)* zlatan ibrahimovic (\w* *)*) I think that I shouldn't put anything around the phrase you want to find. patzln = re.compile(r'.*(zlatan ibrahimovic){1,1}.*') this should do it for you. Unless searching into a special position. In the other hand, I'd like to understand how I can substitute a variable inside a pattern. if I do: import os, re EOL= os.linesep re_EOL= re.compile(r'[?PEOL\s+2\t]')) for line in open('myfile','r').readlines(): print re_EOL.sub('',line) Will it remove tabs, spaces and end-of-line ? It's doing but no EOL :( -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: can't assign to literal
On 00:15, giovedì 12 giugno 2008 Ethan Furman wrote: I like Vim (Vi Improved) What about justifying text ? -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Python doesn't understand %userprofile%
On 00:11, mercoledì 11 giugno 2008 Tim Golden wrote: %USERPROFILE%/dir/file. os.environ('USERPROFILE') should return an info regarding that environment variable. I guess that, not yet tried. -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Formatting Output
On 06:15, martedì 03 giugno 2008 Mensanator wrote: In Access, I create a query with this SQL: But this isn't python itself. I'd like to see a small function to let 'locate' the cursor into a TTY console. Surely it can't scroll. If it is not possible, then ncurses is the way. I don't know if it works on win32. -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: ConfigObj quoting issues
On 14:25, martedì 03 giugno 2008 Roopesh wrote: This error is because of the presence of \', \, \n etc. I had to do the following to make it work. address[i].replace(\','').replace('\','').replace('\n','') it's rather ugly :) I suggest use re module as follow: import re address[i] = re.sub('(`||\n)',re.MULTILINE,address[i]) if you've a big chunck of email it'd be fine to compile the regex. match = re.compile(`||\n) address[i] = match.sub(address[i]) I think there would be a problem with unicode email addresses. But I doubt the existance of unicode addresses nowadays. Unsure for the syntax, pls check http://www.python.org/doc/2.4/lib/re-syntax.html ^^^ according your version, but they're quite the same -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
Shed my a light :)
Hi, I using eval for quite strange reason, as long as I don't know a different way to implement. An example: actions= ('print', 'sum', 'divide', 'myfunction') parameters=(5, 'nothing',5.63, object) for routines in actions: routines(parameters) I'd like to note that actions are string or string expressions of the program functions or python itself, so I've in my program something like: for nn in actions: eval('cp.%s' %nn) Where cp is an instance. So I'm asking here whether exist a way that these string become functions inside my program, without using eval() -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Shed my a light :)
On 19:06, lunedì 02 giugno 2008 Chris wrote: actions= ('print', 'sum', 'divide', 'myfunction') parameters=(5, 'nothing',5.63, object) 8 8 getattr(...) getattr(object, name[, default]) - value 8 8 for nn in actions: func = getattr(cp, nn) if callable(func): func(parameters) I got the point of Duncan and I should remain on evail() because the evaluation is made on a construct of string expression, which give me the final name of the function I want to call. I've tried on Pyshell and clearly said the object str is not callable. Some of those string are functions inside the module, so I was expecting a sequence of calls according the passed in functions names, but they *must* be processed as a python statements ;( -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Shed my a light :)
On 22:00, lunedì 02 giugno 2008 Paul Melis wrote: This doesn't exactly make sense, as what you want isn't really clear... Sorry, I'm bad to express my toughts even I my nature language :) I'll give a go to getattr() and see whether the results come in my taste :) -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: File browser in python gui
On 02:48, domenica 01 giugno 2008 TheSaint wrote: I'm gonna back to study a little I'm facing tough time, I can't get clear by Trolltech's C++ examples. I'm a bit puzzled :), I'd like to remain with the QT widget set, but hard learning curve. Other simplified developing TK are giving different widgets, I don't expect to mix up :( -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: [Business apps for Windows] Good grid + calendar, etc.?
On 19:59, domenica 01 giugno 2008 Gilles Ganault wrote: require rich widgets like (DB)grids, calendars, etc. Qt seems to go a bit further. Try Eric4 as SDK. -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
File browser in python gui
hi there, I've started to build a GUI for my Mailsweeper by the help of QT4 Designer. I came across the problem that there isn't any prebuild file browser like Kdialog. I know some other sample, but PyGTK builded. I'm not happy to use a different widget set or to have to design my own file browser with QT4 widgets. It's almost thousand times people need to use such browser, I wonder why I couldn't find one on the entire day searching on web site. A QT XML file (.ui extension) should do fine, if someone would help :) -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list