Re: Framework for a beginner
On 19.04.2012, Kiuhnm kiuhnm03.4t.yahoo.it wroted: When you know more than 30 languages you stop thinking that way and you also don't try to defend your language against infidels. Then again, even when you know more than 100 languages, you may find some that fit your brain and some that just don't work well with your neurons. And you may still call the former my languages. GS -- Grzegorz Staniak gstaniak _at_ gmail [dot] com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Gotcha's?
On 06.04.2012, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wroted: Are there languages (other than python) in which single and double quotes are equivalent? Classic REXX, CSS, JavaScript, Lua, Prolog, XPath, YAML, Modula-2, HTML, and (of course) English. There may be others. Other languages like Perl, PHP and Ruby support alternate delimiters with slightly different semantics. Perl, first of all, has the 'q' and 'qq' operators. As much as I'd come to dislike Perl after I discovered Python, I miss those two. Every time I have to quote a string full of single/double quotes, this comes to my mind: q{'this' is not this, but 'that' is 'that' like 'this'} q|'this' is not this, but 'that' is 'that' like 'this'| q'this' is not this, but 'that' is 'that' like 'this' ... with 'qq' providing the version with inerpolation. I could always find an arbitrary character for quoting that was _not_ present in the string, and so, most of the time, avoid quoting altogether. It was perhaps a bit too magical, but pruced very readable strings. GS -- Grzegorz Staniak gstaniak _at_ gmail [dot] com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Gotcha's?
On 06.04.2012, rusi rustompm...@gmail.com wroted: This is the 21st century, not 1960, and if the language designer is worried about the trivially small extra effort of parsing ' as well as then he's almost certainly putting his efforts in the wrong place. Yes, that's what you said already. My reasoning was in the part you stripped from my quote. *shrug* Multiple symmetric quote characters breaks one of python's own zen rules: There should be one-- and preferably only one --obvious way to do it. Then again, practicality beats purity. GS -- Grzegorz Staniak gstaniak _at_ gmail [dot] com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Gotcha's?
On 05.04.2012, Roy Smith r...@panix.com wroted: There's absolutely no reason why JSON should follow Python syntax rules. Making it support either kind of quotes would have complicated every JSON library in the world, for no added value. I think these days it's not just Python syntax, it's kinda something that you can get accustommed to take for granted. Realistically, how much more complication could the support for either quote marks introduce? I doubt anyone would even notice. And you don't have to write JSON by hand for this gotcha to bite you, all it takes is to start playing with generating JSON without the use of specialized JSON libraries/functions. For testing, for fun, out of curiosity... GS -- Grzegorz Staniak gstaniak _at_ gmail [dot] com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Gotcha's?
On 05.04.2012, Roy Smith r...@panix.com wroted: There's absolutely no reason why JSON should follow Python syntax rules. Making it support either kind of quotes would have complicated every JSON library in the world, for no added value. I think these days it's not just Python syntax, it's kinda something that you can get accustommed to take for granted. Realistically, how much more complication could the support for either quote marks introduce? I doubt anyone would even notice. And you don't have to write JSON by hand for this gotcha to bite you, all it takes is to start playing with generating JSON without the use of specialized JSON libraries/functions. For testing, for fun, out of curiosity... If you want to talk a protocol, read the protocol specs and follow them. Sure, sure. But it still may raise a few eyebrows as people start to play along while still reading the spces. It's just not something that I'd expect (yes, I learnt Perl before I discovered Python). GS -- Grzegorz Staniak gstaniak _at_ gmail [dot] com -- http://mail.python.org/mailman/listinfo/python-list
Re: random number
On 26.03.2012, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wroted: How can we generate a 6 digit random number from a given number ? what about this? given_number=123456 def rand_given_number(x): ... s = list(str(x)) ... random.shuffle(s) ... return int(''.join(s)) ... print (rand_given_number(given_number)) 653421 That's not very random. In fact, it is *terrible* as a random number generator. But isn't it what the OP requested, i.e. 6 digit random number *from a given number*? That is, a random permutation of the set of its digits? GS -- Grzegorz Staniak gstaniak _at_ gmail [dot] com -- http://mail.python.org/mailman/listinfo/python-list
Data mining/pattern recogniton software in Python?
Hello, I've been asked by a colleague for help in a small educational project, which would involve the recognition of patterns in a live feed of data points (readings from a measuring appliance), and then a more general search for patterns on archival data. The language of preference is Python, since the lab uses software written in Python already. I can see there are packages like Open CV, scikit-learn, Orange that could perhaps be of use for the mining phase -- and even if they are slanted towards image pattern recognition, I think I'd be able to find an appropriate package for the timeseries analyses. But I'm wondering about the live phase -- what approach would you suggest? I wouldn't want to force an open door, perhaps there are already packages/modules that could be used to read data in a loop i.e. every 10 seconds, maintain a a buffer of 15 readings and ring a bell when the data in buffer form a specific pattern (a spike, a trough, whatever)? I'll be grateful for a push in the right direction. Thanks, GS -- Grzegorz Staniak gstaniak _at_ gmail [dot] com -- http://mail.python.org/mailman/listinfo/python-list
Re: Data mining/pattern recogniton software in Python?
On 24.03.2012, Jon Clements jon...@googlemail.com wroted: It might also be worth checking out pandas[1] and scikits.statsmodels[2]. In terms of reading data in a loop I would probably go for a producer-consumer model (possibly using a Queue[3]). Have the consumer constantly try to get another reading, and notify the consumer which can then determine if it's got enough data to calculate a peak/trough. This article is also a fairly good read[4]. That's some pointers anyway, hth, Jon. [1] http://pandas.pydata.org/ [2] http://statsmodels.sourceforge.net/ [3] http://docs.python.org/library/queue.html [4] http://www.laurentluce.com/posts/python-threads-synchronization-locks-rlocks-semaphores-conditions-events-and-queues/ Thanks for the suggestions. GS -- Grzegorz Staniak gstaniak _at_ gmail [dot] com -- http://mail.python.org/mailman/listinfo/python-list
Re: Where to locate existing standard encodings in python
On 11.11.2008, Tim Chase [EMAIL PROTECTED] wroted: (Aside: stupid dilbert.com site developers...what sorta rubbish is utf-8lias?! It's not like it's something that would appear accidentally. It very much looks like an accident during httpd.conf editing, e.g. pasting part of an Alias at the end of the line for AddDefaultCharset or sth like this. GS -- Grzegorz Staniak gstaniak _at_ wp [dot] pl Nocturnal Infiltration and Accurate Killing -- http://mail.python.org/mailman/listinfo/python-list
Re: wildcard match with list.index()
On 10.11.2008, Mr.SpOOn [EMAIL PROTECTED] wroted: is there any way to search elements in a list using wildcards? I have a list of various elements and I need to search for elements starting with 'no', extract them and put in a new list. I was thinking about something like: mylist.index('no*') Of course this doesn't work. I guess there's a way to use the glob module in this situation, but for the specific case I think you can use: start_with_no = (i for i in mylist if i.startswith(no)) GS -- Grzegorz Staniak gstaniak _at_ wp [dot] pl Nocturnal Infiltration and Accurate Killing -- http://mail.python.org/mailman/listinfo/python-list
Re: Workflow engine?
On 08.11.2008, Piotr Chamera [EMAIL PROTECTED] wroted: In a couple of weeks I'm starting a medium-size project (using a web framework) involving a workflow implementation. Are you aware of any open source workflow engines/libraries that I could base the project on? Google returns hist for GoFlow (Django only, from what I can tell), itools.workflow, spiff (AFAIK tied to a CMS), but not much else. I don't think I'll have enough time to get acquinted with Plone and its offer of products. Has anyone here tried any such code? What would you recommend? There are some packages for zope on pypi: Products.DCWorkflow - zope2, cmf hurry.workflow and some extensions - zope3 zope.wfmc - zope3 (not many dependencies on zope3) Thanks, I'll have a look at them. GS -- Grzegorz Staniak gstaniak _at_ wp [dot] pl Nocturnal Infiltration and Accurate Killing -- http://mail.python.org/mailman/listinfo/python-list
Re: Workflow engine?
On 09.11.2008, Tino Wildenhain [EMAIL PROTECTED] wroted: I think that was part of the problem.. you asked if the wheel had already been invented, rather than tell us about the stones you have to haul up a mountain, and whether a wheel is what you need. It's difficult to answer your original question.. someone could have just as easily said that you should consider Sharepoint and not bother writing any code. Aw, come on. The problem was only mentioned, but the question was pretty specific: could you comment on/recommend an open source python workflow engine/module (implied: to go with a web app). Sharepoint doesn't match the description. I think one could assume that if I'm asking about wheels, I need a pointer to a wheel shop, and I'm not instead making a disguised request for people to analyze my problem for me. Well if we can see you are asking for what is the best wheel ... and we can deduct from your mail that you are tying to build a sleigh I can't see how possibly you could deduce anything like that from what I wrote. I need to implement workflow, I asked about workflow. If I was to continue with the metaphor: I asked about a wheel shop and the reply was better think about the rest of the cart, building yourself a set of wheels is a trivial task. Which of course may be true, and of course people with much more experience than I have may implement the required FSMs in half an hour, but that's not what I asked about. [...] And so if you are asking about the best workflow engine to base the work on you are obviously in a similar situation. This question implies that you are maybe not really aware of what a workflow engine is and does apart from the nice word. I'm sorry, but you're misrepresenting my words. I didn't say anything about best workflow engine, I asked for _any_ suggestions or comments. Most of them happened to be along the lines of phew, that's too easy, go bother yourself with the rest of the stuff. The common denonimator of a workflow (state engine) is so simple, the only complexity comes from the environment it needs to drive. So in short: I doubt there is a general solution to the problem. Well, from the little research I did it seems some people try anyway. I doubt they are all just trendy buzzwords lovers. GS -- Grzegorz Staniak gstaniak _at_ wp [dot] pl Nocturnal Infiltration and Accurate Killing -- http://mail.python.org/mailman/listinfo/python-list
Workflow engine?
Hi, In a couple of weeks I'm starting a medium-size project (using a web framework) involving a workflow implementation. Are you aware of any open source workflow engines/libraries that I could base the project on? Google returns hist for GoFlow (Django only, from what I can tell), itools.workflow, spiff (AFAIK tied to a CMS), but not much else. I don't think I'll have enough time to get acquinted with Plone and its offer of products. Has anyone here tried any such code? What would you recommend? TIA, GS -- Grzegorz Staniak gstaniak _at_ wp [dot] pl Nocturnal Infiltration and Accurate Killing -- http://mail.python.org/mailman/listinfo/python-list
Re: Workflow engine?
On 08.11.2008, Tino Wildenhain [EMAIL PROTECTED] wroted: In a couple of weeks I'm starting a medium-size project (using a web framework) involving a workflow implementation. Are you aware of any open source workflow engines/libraries that I could base the project on? Google returns hist for GoFlow (Django only, from what I can tell), itools.workflow, spiff (AFAIK tied to a CMS), but not much else. I don't think I'll have enough time to get acquinted with Plone and its offer of products. Has anyone here tried any such code? What would you recommend? I would recommend to start with a problem, rather then with a solution. There is not so much magic in workflows as you might seem to think. After all its just maintaining a state and rules for possible transitions. Sure, and I know more or less how I'd do it if I had to code from scratch. On the other hand, I don't want to code from scratch - if there are other viable options. I'm not a genius, but I think I'd manage to write a web framework too - do you really think it would be a good idea to start writing another one? I'd much prefer an existing workflow project that I could use, test, and contribute to, just as I decided on TG for the web thing. GS -- Grzegorz Staniak gstaniak _at_ wp [dot] pl Nocturnal Infiltration and Accurate Killing -- http://mail.python.org/mailman/listinfo/python-list
Re: Workflow engine?
On 08.11.2008, Stefan Behnel [EMAIL PROTECTED] wroted: In a couple of weeks I'm starting a medium-size project (using a web framework) involving a workflow implementation. Are you aware of any open source workflow engines/libraries that I could base the project on? Google returns hist for GoFlow (Django only, from what I can tell), itools.workflow, spiff (AFAIK tied to a CMS), but not much else. I don't think I'll have enough time to get acquinted with Plone and its offer of products. Has anyone here tried any such code? What would you recommend? I would recommend to start with a problem, rather then with a solution. There is not so much magic in workflows as you might seem to think. After all its just maintaining a state and rules for possible transitions. Sure, and I know more or less how I'd do it if I had to code from scratch. On the other hand, I don't want to code from scratch - if there are other viable options. I'm not a genius, but I think I'd manage to write a web framework too - do you really think it would be a good idea to start writing another one? I think Tino was more referring to the fact that state machines are too trivial to write in Python to merit a whole framework. http://www.google.de/search?q=python+state+machine To be exact, I used the words engine/library, not a whole framework. Thanks for the link, I've googled for articles and recipes myself and as I said, I more or less know what to do - I just thought it might be a good idea to ask whether perhaps the wheel has already been invented. Apparently I was wrong. GS -- Grzegorz Staniak gstaniak _at_ wp [dot] pl Nocturnal Infiltration and Accurate Killing -- http://mail.python.org/mailman/listinfo/python-list
Re: Workflow engine?
On 08.11.2008, Eric Wertman [EMAIL PROTECTED] wroted: To be exact, I used the words engine/library, not a whole framework. Thanks for the link, I've googled for articles and recipes myself and as I said, I more or less know what to do - I just thought it might be a good idea to ask whether perhaps the wheel has already been invented. Apparently I was wrong. I think that was part of the problem.. you asked if the wheel had already been invented, rather than tell us about the stones you have to haul up a mountain, and whether a wheel is what you need. It's difficult to answer your original question.. someone could have just as easily said that you should consider Sharepoint and not bother writing any code. Aw, come on. The problem was only mentioned, but the question was pretty specific: could you comment on/recommend an open source python workflow engine/module (implied: to go with a web app). Sharepoint doesn't match the description. I think one could assume that if I'm asking about wheels, I need a pointer to a wheel shop, and I'm not instead making a disguised request for people to analyze my problem for me. GS -- Grzegorz Staniak gstaniak _at_ wp [dot] pl Nocturnal Infiltration and Accurate Killing -- http://mail.python.org/mailman/listinfo/python-list
Re: A bit weird dictionary behavior
On 22.09.2008, Carl Banks [EMAIL PROTECTED] wroted: but it still doesn't feel exactly right. Would it be worth submitting a bug? It feels wrong because it is. In a tidier language (Pascal, Java, etc) a boolean and an integer must be different types. Some would argue (and some did by the time Python grew a 'bool' type) that what is wrong is to have a bool type in a language that already have a wider definition of the truth value of an expression... And some would argue that it was wrong to have such a wide definition for the truth value of an expression in the first place... Just out of idle curiosity, what could be the alternatives? Not to evaluate e.g. strings to true? Aren't such conventions as whatever is not empty, is 'true' popular in dynamic langauges? GS -- Grzegorz Staniak gstaniak _at_ wp [dot] pl Nocturnal Infiltration and Accurate Killing -- http://mail.python.org/mailman/listinfo/python-list
Re: PHP's str_replace ?
On 10.09.2008, Anjanesh Lekshminarayanan [EMAIL PROTECTED] wroted: In PHP, if I do str_replace(array('a', 'e', 'i', 'o', 'u'), '-', $str) it'll replace all vowels with a hyphen in string $str. Is there some equivalent in Python ? The .translate() method of strings? import string mystr = This is just a test transtable = string.maketrans(aeiouy,--) mystr.translate(transtable) 'Th-s -s j-st - t-st' GS -- Grzegorz Staniak gstaniak _at_ wp [dot] pl Nocturnal Infiltration and Accurate Killing -- http://mail.python.org/mailman/listinfo/python-list
Re: PHP's str_replace ?
On 10.09.2008, Anjanesh Lekshminarayanan [EMAIL PROTECTED] wroted: In PHP, if I do str_replace(array('a', 'e', 'i', 'o', 'u'), '-', $str) it'll replace all vowels with a hyphen in string $str. Is there some equivalent in Python ? The .translate() method of strings? import string mystr = This is just a test transtable = string.maketrans(aeiouy,--) mystr.translate(transtable) 'Th-s -s j-st - t-st' GS -- Grzegorz Staniak gstaniak _at_ wp [dot] pl Nocturnal Infiltration and Accurate Killing -- http://mail.python.org/mailman/listinfo/python-list
Re: PHP's str_replace ?
On 10.09.2008, David Thole [EMAIL PROTECTED] wroted: new_str = re.sub('[aeiou]', '-', str) Wow - this is neat. Thanks But probably slower and definitely harder to understand. For simple problems the str methods are usually faster than a regular expression. It's true that regular expressions are generally slower, but I disagree that it's hard to understand. When dealing with text, I think it's an absolute must that programmers know about regular expressions. I think this here is an example where even str_replace in Python wouldn't have worked well. What about mystring.translate(transtable)? GS -- Grzegorz Staniak gstaniak _at_ wp [dot] pl Nocturnal Infiltration and Accurate Killing -- http://mail.python.org/mailman/listinfo/python-list
Re: Equivalents of Ruby's ! methods?
On 25.08.2008, Terry Reedy [EMAIL PROTECTED] wroted: The newish sorted() and reversed() built-ins were meant to complement list.sort and list.reverse, not replace them. BTW, is there a reason why sorted() on a list returns a list, while reversed() on the same list returns an iterator? GS -- Grzegorz Staniak gstaniak _at_ wp [dot] pl -- http://mail.python.org/mailman/listinfo/python-list
Re: Total No. of Records in a File?
On 23.08.2008, W. eWatson [EMAIL PROTECTED] wroted: Maybe. I could see it if the file were truly in a record format. The # of records might be kept by the OS. It's conceivable that Python or the OS might see a file with a CR as recordized. Isn't it much easier to use a database instead? That's what they're made for. How about in a slightly different case. Suppose I want to know the number of files in a folder? The OS and maybe some Python method might know that. Use os and os.path. For a simple case the length of os.listdir() could suffice, but then you might need to filter out sub-directories, or maybe count files in them too using os.walk(). GS -- Grzegorz Staniak gstaniak _at_ wp [dot] pl -- http://mail.python.org/mailman/listinfo/python-list
Re: ??????: How to use win32com to convert a MS WORD doc to HTML ?
On 2008-08-20, Lave [EMAIL PROTECTED] wroted: It's solved. Thank you all! You saved my life! Thank you very much. I love you! I love Python! ... I love the whole world, and all its languages, Boom-de-yada, boom-de-yada, boom-de-yada, boom-de-yada... Very sorry, but I just couldn't resist. GS -- Grzegorz Staniak gstaniak _at_ wp [dot] pl -- http://mail.python.org/mailman/listinfo/python-list
Re: simple Question about using BeautifulSoup
On 2008-08-20, Alexnb [EMAIL PROTECTED] wroted: Okay, I have used BeautifulSoup a lot lately, but I am wondering, how do you open a local html file? Usually I do something like this for a url soup = BeautifulSoup(urllib.urlopen('http://www.website.com') but the file extension doesn't work. So how do I open one? Have you tried the local file URL, like file:///home/user/file.html? GS -- Grzegorz Staniak gstaniak _at_ wp [dot] pl -- http://mail.python.org/mailman/listinfo/python-list
Re: like a for loop for a string
On 2008-08-17, Alexnb [EMAIL PROTECTED] wroted: Basically I want the code to be able to pick out how many strings What do you mean by string? foo = abc abc cde abc ijk abc cde abc foo is one string. If you want substrings, specify what kind of substrings you mean. All occurences of abc, for example. there are and then do something with each, or the number. When I say string I mean how many strings are in the string string string string non-string string Do you mean something like count and return all occurences of the substring 'abc' in foo? Looks like you should use the re module. GS -- Grzegorz Staniak gstaniak _at_ wp [dot] pl -- http://mail.python.org/mailman/listinfo/python-list
Re: like a for loop for a string
On 2008-08-17, Alexnb [EMAIL PROTECTED] wroted: string = yes text1 yes text2 yes text3 no text4 yes text5+more Text yes text6 no text7 yes text8 It doesn't matter what is in the string, I want to be able to know exactly how many yes's there are. - cut here - import re foo = yes text1 yes text2 yes text3 no text4 yes text5+more Text yes text6 no text7 yes text8 results = re.findall(yes, foo) len(results) 6 results ['yes', 'yes', 'yes', 'yes', 'yes', 'yes'] - cut here - I also want to know what is after each, regardless of length. So, I want to be able to get text1, but not text4 because it is after no and I want all of text5+more Text because it is after yes. It is like the yeses are bullet points and I want all the info after them. However, all in one string. I guess this can be done with regular expressions: http://www.python.org/doc/current/lib/module-re.html Read about groups, then write an appropriate regex. GS -- Grzegorz Staniak gstaniak _at_ wp [dot] pl -- http://mail.python.org/mailman/listinfo/python-list