disgrating a list
Hello, How can I disgrate (probably not a good word for it) a list? For example: a = [1,2] b = 3 c = [a] + [b] # which makes [[1,2],3] Then how can I change c ([[1,2],3]) into [1,2,3]? I have a simple function for this: def flatten(l): r = [] s = [l] while len(s) 0: i = s.pop() if i.__class__ == list: for c in i: s.append(c) else: r.append(i) return r But this function isn't really doing it in the python-way. Doesn't have python an obscure function or buildin to do this? Greetz, Noud Aldenhoven -- http://mail.python.org/mailman/listinfo/python-list
Re: disgrating a list
Diez B. Roggisch wrote: Why do you wrap a in a list? Just c = a + [b] will do it. Yes I know, but the problem is I don't know if 'a' is a list or not. I could make a type check, but I don't want to program in that way. Noud -- http://mail.python.org/mailman/listinfo/python-list
Re: disgrating a list
Thank you for all your reply and support. Neil's fits the most to me. I shrinked it to this function: def flatten(x): for i in range(len(x)): if isinstance(x[i], list): x[i:i+1] = x[i] Thank you all again. If someone could find even a cuter way, I'd like to see that way. Noud Aldenhoven -- http://mail.python.org/mailman/listinfo/python-list
Re: f*cking re module
To reply to the last part of the discussion and esspecially to Gustavo Niemeyer, I really apriciate the way in which I had been answered. And I won't have any questions about the re module that I had before I post this threat. I was frustration and should, probebly, not post this frustration. But it was never my purpous to ask something stupid or asking it arrogant. The python re module is, in my opinion, a non beginner user friendly module. And it's not meant for beginning python programmers. I don't have any experience with perl or related script/programming languages like python. (I prefer to do things in c) So the re module is completely new for me. If I upset someones clean mind posting a stupid and arrogant question, I'm sorry and won't post my frustrasion on this usenet group anymore. But thank you for all your help about the re module, Noud Aldenhoven -- http://mail.python.org/mailman/listinfo/python-list
f*cking re module
arg... I've lost 1.5 hours of my precious time to try letting re work correcty. There's really not a single good re tutorial or documentation I could found! There are only reference, and if you don't know how a module work you won't learn it from a reference! This is the problem: import re str = blablapythonRe modules sucks!/pythonblabla re.search((python)(/python), str).group() Traceback (most recent call last): File stdin, line 1, in ? AttributeError: 'NoneType' object has no attribute 'group' the only thing I want are the number of places blabla, Re modules sucks! and blabla are. Noud -- http://mail.python.org/mailman/listinfo/python-list
Re: f*cking re module
Thank you for your replies, it's much obvious now. I know more what I can and can't do with the re module. But is it possible to search for more than one string in the same line? bv. I want to replace the python with /python with \n and every thing that's not between the two python tags must begin with \nprint \\\ and end with n? Or do I need more than one call? -- http://mail.python.org/mailman/listinfo/python-list
website catcher
Hello, I'm busy to build some kind of webpage framework written in Python. But there's a small problem in this framework. This framework should open a page, parse it, take some other information out of it and should store it in some kind of fast storage. This storage need to be very fast so every one who will ask for this page will get a parsed page returned from this storage (catcher?). But how could I design a good webcatcher? Is this possible in python, because it should always run. Which won't work with cgi-bin pages because the quit after the execute something. Or should it be build in c and imported as a module or something? Thank you, Noud Aldenhoven -- http://mail.python.org/mailman/listinfo/python-list
Re: website catcher
Thank you, but it's not what I mean. I don't want some kind of client parser thing. But I mean the page is already been parsed and ready to be read. But I want to store this page for more use. I need some kind of database that won't exit if the cgi-bin script has finished. This database need to be open all the time and communicate very easily with the cgi-bin framwork main class. -- http://mail.python.org/mailman/listinfo/python-list
Re: website catcher
If I should put the parsedwebsites in, for example, a tablehash it will be at least 5 times faster than just putting it in a file that needs to be stored on a slow harddrive. Memory is a lot faster than harddisk space. And if there would be a lot of people asking for a page all of them have to open that file. if that are 10 requests in 5 minutes there's no real worry. If they are more that 10 request per second you really have a big problem and the framework would probably crash or will run uber slow. That's why I want to open the file only one time and keep it saved in the memory of the server where it don't need to be opened each time some is asking for it. Noud Aldenhoven -- http://mail.python.org/mailman/listinfo/python-list
Re: website catcher
Well, thank you for your advice. So I have a couple of solutions, but it can't become a server at its own so this means I will deal with files. Thank you for your advice, I'll first make it work... than the server. Noud Aldenhoven -- http://mail.python.org/mailman/listinfo/python-list
Re: execute python code and save the stdout as a string
Thank you, this really looks cool! -- http://mail.python.org/mailman/listinfo/python-list
execute python code and save the stdout as a string
Hello, I've a question. Can I execute a part of a python code and put it's output in a string? Something like this: s = s = exec print Hello World print s Greetz, Noud -- http://mail.python.org/mailman/listinfo/python-list
Re: blabla
Peter Maas wrote: Noud Aldenhoven schrieb: Python rulz and sorry for this spam... news.test is made for testing :) I really should appoligize for this spam, I though I couldn't post it but actually it did. I was trying to get Pan running, but I couldn't find a place where I could put my authorisation for the smtp server. So I though I could post something and it would never be sent. But it did... Sorry, Jwaixs -- http://mail.python.org/mailman/listinfo/python-list