Re: PDF with nonLatin-1 characters
Stefan Behnel wrote: > victor wrote: > > I want to generate a report and the PDF fits perfectly. Though there is > > an issue of using different encoding in the doc. I tried PyPS with no > > success. I need a lib that can make PDFs with an arbitrary set of fonts > > (possibly embed them into the document). What would you suggest? > > I'd suggest generating LaTeX code and using PDFlatex. It's pretty hard to get > better results from any other tool. > > Stefan I agree that LaTeX is great in most cases - but it is a bit tricky to learn if you are not used to it. There is something called txt2tags ( http://txt2tags.sourceforge.net/ ) that converts a simple textformat to most other formats (from "text" to html, tex, man etc) - I have not tried it fully, it could be nice, but it disturbs me that the format is (just a little) different from the wiki-format. It is written in python and has open source I think. /Per - yet another yet-another-fan http://www.pererikstrandberg.se -- http://mail.python.org/mailman/listinfo/python-list
Re: Very good Python Book. Free download : Beginning Python: From Novice to Professional
Hi, I hope you all know about wikibooks, it's like wikipedia but for books. It is also "some kind of openware" (my favourite expression). I specifically think about http://en.wikibooks.org/wiki/Programming:Python I have thought about adding to it but I am low on time - this randomchoice(["is","could be"]) a great book. Please read and/or add if you are one of the nice guys. Ciao, PER9000 "It is a gift. A gift to the foes of 'the Terrorists'. Why not use this 'terrorism'? Long has my father, 'George Bush', kept the forces of 'the terrorists' at bay. By the blood of our people are your lands kept safe. Give 'the land of the brave' the weapon of the enemy. Let us use it against him." /George W Bush on the topic of Human rights (not really, it's from http://www.imdb.com/title/tt0120737/quotes ) -- http://mail.python.org/mailman/listinfo/python-list
Re: create a text file
Hi, This is what I often do: somekindofoutput = '' somekindofoutput += somefunk(somearg) + '\n' # w is for writing myfile = open('theoutfile',w) myfile.write(somekindofoutput) myfile.close() also see http://www.python.org/doc/2.3.5/tut/node9.html or some other documentation /P9k -- http://mail.python.org/mailman/listinfo/python-list
Re: create a text file
Ooops, w must be 'w' - sorry for adding more confusion :-D I would also like to add that this is a more realistic useage appendix = '.txt' # or '.csv' or whatever # some code c += 1 filetitle = 'result_' + zeropadding(c) + str(c) myfile = open(filetitle+appendix,'w') # etc Hope that was a little better. /P9K -- http://mail.python.org/mailman/listinfo/python-list
Re: How to truncate/round-off decimal numbers?
Hi, just a thought: if you *always* work with "floats" with two decimals, you are in fact working with integers, but you represent them as a floats - confusing for the internal representation. So why not work with int(float * 100) instead? This way you only have to take care of roundoffs etc when dividing. "int (+|-|*) int" = int "int / int" = int / int + int % int Integers are nice, me like integers. /per9000 -- http://mail.python.org/mailman/listinfo/python-list
Re: How to truncate/round-off decimal numbers?
oops, should be something like this: "int / int" = "int / int, int % int" /per9000 -- http://mail.python.org/mailman/listinfo/python-list
Re: How to truncate/round-off decimal numbers?
Nick Maclaren wrote: > |> just a thought: if you *always* work with "floats" with two decimals, > |> you are in fact working with integers, but you represent them as a > |> floats - confusing for the internal representation. > > No, you aren't - you are working with fixed-point Nick, your answer has so many layers, I'll try to explain how I think :-D 1) if you use integers you can think of them as having one part bigger than 100 and one part smaller than 100, like so: >>> a = 11122 >>> (a/100,a%100) (111, 22) Here the output 111,22 looks like something else than an integer, but this is just a matter of representation. a *is* an integer, but we represent it *as if it was* a "decimal" number. (Compare with (minutes,seconds) or (euro,cents) or (feet,inch) or any other "arbitrary" position system) 2) If we use floats with two decimals >>> b = 222.33 >>> b 222.330001 they look like fix-point numbers (I had to look it up http://en.wikipedia.org/wiki/Fixed-point :-D) but python stores it (correct me if I am wrong) as a float (or double or quad or whatever). If we want to work with fix-point aritmetics we have to invent new functions to do most math. 3) Most "decimal numbers" cannot be stored exactly as floats - that is why b gave the ugly print. But some can, f.x >>> quart = 0.25 >>> quart 0.25 quart translates to a finite "decimal" number in binary (0.01 I think). The point is: representing should-be integers as floats makes you loose precision (negligable probalby but still...). 4) > |> So why not work with int(float * 100) instead? This way you only have > |> to take care of roundoffs etc when dividing. > > And multiplying, and calling most mathematical functions. You are correct of course. My mistake. But, the multiplication is exact before you start rounding off - I wont start counting ordos for int*int vs. float*float, but it could have some advantages >>> a 11122 >>> b 22233 >>> a*b 247275426 >>> (a*b/1,a*b%1) (24727, 5426) On the other hand you will quickly loose accuracy if you perform multiple multiplications or divisions or use other mathematical functions. 5) So, when could this way of thinking be useful? Well, rarely, but if you only add/subtract "decimals" and/or multiply "decimals" with whole numbers or if you want to use some non-metric system to do scientific stuff (compute square feet when having (feet1,inch1) * (feet2,inch2) assuming that inches are atomic.) This could of course be extended to (feet, inch, quarter_of_afoot, sixteeth_of_a_foot) if you'd like - it is all a matter of representation. Regards, Per "It is a gift. A gift to the foes of 'the Terrorists'. Why not use this 'terrorism'? Long has my father, 'George Bush Sr', kept the forces of 'the terrorists' at bay. By the blood of our people are your lands kept safe. Give 'the land of the brave' the weapon of the enemy. Let us use it against him." -- http://mail.python.org/mailman/listinfo/python-list
compiling python (or ironpython) to .exe or .dll for or not for .NET
Hi python people, I am working with .NET (in C++/CLI and C#) but since I really love python I'd like to do things for .NET (or whatever) from python. Has anyone tried it? What (costless) compilers are good? Are there any (costless) editors like MS Visual Express you have tried? Is the newest Ironpython really as old as from 2004 July 28 (as stated on http://www.ironpython.com/)? Thanks. /Per Erik Strandberg yet another Fibonaccilover -- http://mail.python.org/mailman/listinfo/python-list
Re: compiling python (or ironpython) to .exe or .dll for or not for .NET
Update: I have found a holy handgrenade. I found something that seems to work fine for me - I've only tried it for 5 minutes but seems to work very smoothly. Open-source, Mozilla license, you know the drill... http://www.py2exe.org/ py2exe (the name makes me fall in love) creates some dll's for me containing python I guess. 2006-06-28 23:26 . 2006-06-28 23:26 .. 2005-09-28 13:4177 824 bz2.pyd 2006-06-28 23:2619 456 fib.exe 2006-06-28 23:26 641 449 library.zip 2003-02-21 04:42 348 160 MSVCR71.dll 2005-09-28 13:41 1 867 776 python24.dll 2005-09-28 13:41 405 504 unicodedata.pyd 2005-09-28 13:41 4 608 w9xpopen.exe 2005-09-28 13:4169 632 zlib.pyd 8 File(s) 3 434 409 bytes My goal here is some kind of fibonacci stuff, preferably for dot net, but the extremely clean code in python (that deals with fibonaccinumbers that are large beyond being silly) dies in C*. I have to build my own sillyINT class and I don't like building sillyINT classes. Before I depress the enter button it finds that the number 123456789012345678901234567890123 has the nearest smaller and larger fibonacci numbers: 110560307156090817237632754212345 and 178890334785183168257455287891792. And my code remains hidden (I guess). Has someone tried some other (costless) holy handgrenade that does the trick? /Per Erik Strandberg yet another FibonacciNumerologist -- http://mail.python.org/mailman/listinfo/python-list
Re: Python CGI Scripting Documentation
Hi, I wanted to try this myself a few days ago, my first (working) try had this source code: --- #!/usr/bin/python print 'Content-Type: text/plain' print print 'hell o world' --- (the output is just "hell o world\n", but the first four lines are still required I guess, I don't know why, but it works...) The file had to be named filetitle + ".cgi" because of some setting at my web hotel. Good luck! /Per9000 -- http://mail.python.org/mailman/listinfo/python-list
problem(s) with import from parent dir: "from ../brave.py import sir_robin"
Dear Black Knight, I have no quarrel with you sir Knight, but I must import your parents. SHORT VERSION: I tried three variants of "from ../brave.py import sir_robin", one works. I want to use it in a py-file to execute command-line-style and that does not work. Can someone please give me, not a bucket with the desert(s) on top, but just the thin chocolate? /per9000 (per nine thousand at gmail dot com) LONG VERSION: Since I do not want to use absoute paths I want to import a file from two folders up and then one down. This problem seems to be discussed in: http://starship.python.net/pipermail/python-au/2005/000543.html I tried following it but I did not understand and/or try hard enough and/or my father smells of elderberrys. So... ...first I tried this: "from ../brave.py import sir_robin" (and variants) But all I got was syntax or import error(s). -- Then I tried to fool python by walking the path up with os.chdir('..') in the line-by-line interpreter. This (surprisingly) worked just fine. C:\my\holy\grail\that_old_bridge>python >>> import os >>> os.chdir('../../py_scripts') >>> os.getcwd() 'C:\\my\\holy\\py_scripts' >>> from raw2nice_def import raw2nice >>> os.listdir('.') ['raw2nice_def.py', 'raw2nice_def.pyc', 'temp'] >>> raw2nice -- When I tried putting this into a program to execute command-line-style: the interesting code: import os cwd = os.getcwd() os.chdir('../../py_scripts') print os.listdir('.') from raw2nice_def.py import raw2nice os.chdir(cwd) output: > "C:\another_bridge\python\python.exe" rawhtml2nicehtml_template.py ['raw2nice_def.py', 'raw2nice_def.pyc', 'temp'] Traceback (most recent call last): File "C:my\holy\grail\that_old_bridge\rawhtml2nicehtml_template.py", line 10, in ? from raw2nice_def.py import raw2nice ImportError: No module named raw2nice_def.py The worst part here is that os.listdir('.') returns ['raw2nice_def.py', 'raw2nice_def.pyc', 'temp'] - meaning (to me) that Python really should "feel" my nice file but somehow still does not see it. To me this also means that python::command_line does not concurr with python::line_by_line(!?!) Can someone please give me, not a bucket with the desert(s) on top, but just the thin chocolate? /per9000 (per nine thousand at gmail dot com) -- http://mail.python.org/mailman/listinfo/python-list
Re: problem(s) with import from parent dir: "from ../brave.py import sir_robin"
Thanks, I added an environment variable PYTHONPATH and added the holy folder with my script in. Works just perfectly. But still: is there a way around this? (It is a lot easier to add "../../" in my code than make everyone else add this variable). /per9000 -- http://mail.python.org/mailman/listinfo/python-list
Re: problem(s) with import from parent dir: "from ../brave.py import sir_robin"
...and there was much rejoicing... Even better, thanks - you guys are the best. import string, time, sys sys.path.append("../../py_scripts") Works just nice, and yes, I removed the env.variable before I tried it :-D /Per9000 -- http://mail.python.org/mailman/listinfo/python-list
magic names in python
Hi, I recently started working a lot more in python than I have done in the past. And I discovered something that totally removed the pretty pink clouds of beautifulness that had surrounded my previous python experiences: magic names (I felt almost as sad as when I discovered the strange pink worms that eat you in nethack, not to mention the mind flayers - I really hate them). I guess all programming languages have magic names to some extent (f.x. classes in the "C-family" have constructors that must have the same name as the class (foo::foo) instead of foo.__init__). I just used a search engine a little on this topic and I found no comprehensive list of magic names in python. So my questions: * is there a comprehensive list of magic names in python (so far i know of __init__ and __repr__)? * are these lists complete or can magic names be added over time (to the python "core")? * are magic names the same in different python versions? I also tried (selected parts of(?)) the unittest package for use in Zope and it seemed functions that I created for my test with the magic prefix "test" were magic, other functions were not. So another question emerges: * is the use of magic names encouraged and/or part of good coding practice. Live long and prosper, Per -- Per Erik Strandberg home: www.pererikstrandberg.se work: www.incf.org also: www.spongswedencare.se -- http://mail.python.org/mailman/listinfo/python-list
Re: magic names in python
On Jun 4, 9:11 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > In <[EMAIL PROTECTED]>, per9000 wrote: > > > > [...] > > > > So another question emerges: > > * is the use of magic names encouraged and/or part of good coding > > practice. > > What do you mean by "use"? Implement them to override behavior? Yes, > that's their purpose. Invent new magic names? No of course not, they are > special for a reason: preventing name clashes with the user's names. > [in my taste: UGLY] I think of something like this: Perhaps I create a class that works with a lot of files, and with inheritance new types of files can be opened and worked with. When it is time for an instance of this class to die the files need to be closed - perhaps "right now" and not when it is suitable for the garbage collector. To facilitate this I create a number of functions with names like close_*_file (f.x. close_indata_file, close_outdata_file, close_error_file etc). (compare with [PyTest| unittest] "test*" names.) If this class has been inherited to some other class that works with more than one indata file perhaps we want to magically close all files that are open by calling all function in this instance that has names matching "close_*_file". I would consider this an ugly way of solving it. [in my taste: NICER] I'd perhaps add file-handles to some list (and encourage inherited classes to use this list) and close everything in the list. I would not use magic wildcard names. So in other words: Do I need to go to yellow alert, and watch out for magic names in non-core add-on packages to python? Or should I just RTFM a little more? (I hate RTFM'ing.) Live long and prosper, Per -- Per Erik Strandberg home: www.pererikstrandberg.se work: www.incf.org also: www.spongswedencare.se -- http://mail.python.org/mailman/listinfo/python-list
Re: magic names in python
On 4 Juni, 10:19, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > > [...] > > Now I'm a little confused. What does this have to do with magic names? I > thought you are talking about names that start and end with two > underscores (`__magic__`)!? Indeed I am talking about two things at once - you are right. Since I have problems with both of these "features" I perhaps do not separate them very well. I received lots of nice links to __special__ names in python, thanks. When it comes to 'dive into python' this is like the fifth time I heard of it so I really have to get it soon. Still, I have problems with "magic" functions, similar to magic numbers: http://en.wikipedia.org/wiki/Magic_number_%28programming%29 f.x. calling all member-functions of a class to close files as illustrated in a previous post, or PyUnits magic "test*"-names: http://pyunit.sourceforge.net/pyunit.html#RUNNING_CMD (there are options here but I fell into the bear-trap of course) Guessing from your replies this is a general problem/issue/feature and as I understand it there is no special pythonic recommendations in this area, right? Also, I guess that use of magic numbers and magic should be documented and are thus discovered by RTFM'ing. Additional comments are welcome, or course. All your base are belong to us, Per -- Per Erik Strandberg home: www.pererikstrandberg.se work: www.incf.org also: www.spongswedencare.se -- http://mail.python.org/mailman/listinfo/python-list
Re: magic names in python
On 5 Juni, 11:02, ai <[EMAIL PROTECTED]> wrote: > I don't think it is magic. If you think it is magic, can you talk > about what's the better way and how can you implement the functions > without any magic. [...] Well, in a sense I guess all reserved words can be considered magic, but in Python you can kill it (AFAIK that is pretty unique to python): >>> a = int(8) >>> int = float >>> b = int(8) >>> (a, b) (8, 8.0) I guess the amount and flavor of the magic is a matter of personal taste - coming from a C*-background I pretty much like myClass.myClass() instead of myClass.__init__() - but these are equivalent and I guess I just have to live with the way python has __special__ names and print a list of the cases I end up with often to keep my memory from forgetting them. > There are some special names even in Lisp. I guess you just hate the > '__'. Yes and no. Indeed, I find the overuse of underscores ugly, but I can accept some use of __special__ functions. AFAIK there must be reserved words in a programming language - f.x. names of ctors in oo-languages. The exceptions are perhaps brainf**k and whitespace that has special chars instead. Also I find it unfortunate that the name mangling and underscores are the way to make members "less public". But I can live with that - I just have to read more python code to get the hang of it. [:)]-|--< /Per -- Per Erik Strandberg home: www.pererikstrandberg.se work: www.incf.org also: www.spongswedencare.se > > On Jun 4, 2:43 pm, per9000 <[EMAIL PROTECTED]> wrote: > > > Hi, > > > I recently started working a lot more in python than I have done in > > the past. And I discovered something that totally removed the pretty > > pink clouds of beautifulness that had surrounded my previous python > > experiences: magic names (I felt almost as sad as when I discovered > > the strange pink worms that eat you in nethack, not to mention the > > mind flayers - I really hate them). > > > I guess all programming languages have magic names to some extent > > (f.x. classes in the "C-family" have constructors that must have the > > same name as the class (foo::foo) instead of foo.__init__). > > > I just used a search engine a little on this topic and I found no > > comprehensive list of magic names in python. > > > So my questions: > > * is there a comprehensive list of magic names in python (so far i > > know of __init__ and __repr__)? > > * are these lists complete or can magic names be added over time (to > > the python "core")? > > * are magic names the same in different python versions? > > > I also tried (selected parts of(?)) the unittest package for use in > > Zope and it seemed functions that I created for my test with the magic > > prefix "test" were magic, other functions were not. > > > So another question emerges: > > * is the use of magic names encouraged and/or part of good coding > > practice. > > > Live long and prosper, > > Per > > > -- > > > Per Erik Strandberg > > home:www.pererikstrandberg.se > > work:www.incf.org > > also:www.spongswedencare.se -- http://mail.python.org/mailman/listinfo/python-list
Re: test
On 2 Maj, 05:19, "Robert Rawlins - Think Blue" <[EMAIL PROTECTED]> wrote: [...] I like comp.lang.python - it is a friendly place. See this post on the C-list and compare: http://groups.google.se/group/comp.lang.c/browse_thread/thread/0a4e2e194a6da45b [:)]-|--< /Per -- Per Erik Strandberg .NET Architect - Optimization Tomlab Optimization Inc. http://tomopt.com/tomnet/ -- http://mail.python.org/mailman/listinfo/python-list
encrypting files + filestreams?
Hi python people, I am trying to figure out the best way to encrypt files in python. I've build a small script (see below) that encrypts the ubuntu 7.04 iso file in 2 minutes (I like python :) ). But I have some thoughts about it. By pure luck (?) this file happened to be N*512 bytes long so I do not have to add crap at the end - but on files of the size N*512 + M (M != 521) I will add some crap to make it fit in the algorithm. When I later decrypt I will have the stuff I do not want. How do people solve this? (By writing the number of relevant bytes in readable text in the beginning of the file?) Also I wonder if this can be solved with filestreams (Are there streams in python? The only python file streams I found in the evil search engine was stuff in other forums.) Other comments are of course also welcome, Per # crypto_hardcoded.py starts here from Crypto.Cipher import AES def encrypt2(cryptor, infile, outfile): """enly encrypt a few bytes at a time""" size = 512 bytes = infile.read(size) seek = 0 interval = 97 ctr = 0 while len(bytes) == size: seek += size if ctr % interval == 0: print '\r%15d bytes completed' % (seek), ctr += 1 outfile.write(cryptor.encrypt(bytes)) # change to this to decrypt # outfile.write(cryptor.decrypt(bytes)) bytes = infile.read(size) if len(bytes) != 0: bytes += "#" * (size - len(bytes)) outfile.write(cryptor.encrypt(bytes)) seek += len(bytes) print '\r%15d bytes completed' % (seek) if __name__ == "__main__": crptz = AES.new("my-secret_passwd") ifile = file('/tmp/ubuntu-7.04-desktop-i386.iso','r') ofile = file('/tmp/ubuntu-7.04-desktop-i386.iso.out','w') encrypt2(crptz, ifile, ofile) ifile.close() ofile.close() # crypto_hardcoded.py ends here -- http://mail.python.org/mailman/listinfo/python-list
reaching hidden methods + casting
Hi, can I reach a hidden method when doing ugly inheritance in python? >>> class A: ... def spin(self, n): print "A", n ... >>> class B: ... def spin(self, m): print "B", m ... >>> class C(A,B): ... def spin(self, k): print "C", k ... >>> myC = C() >>> dir(myC) ['__doc__', '__module__', 'spin'] In f.x. the C-family of languages I guess something like this would call B.spin: ((B)myC).spin("Lancelot"); // almost forgot the ';' Please correct me I am wrong (which I likely am) but as I understand it this example calls the constructor of int instead of casting it, right? >>> leet = int('1337') >>> leet 1337 So is there another way of digging into the past of a class? Or can/ should I create constructors for the classes A, B and C that takes objects of the other classes? Or should I have thought about getting unique names before I implemented the ugly inheritance graph? /Per -- Per Erik Strandberg blog: http://www.pererikstrandberg.se/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Re: reaching hidden methods + casting
On 12 Apr, 09:42, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > > > > > In f.x. the C-family of languages I guess something like this would > > call B.spin: > > ((B)myC).spin("Lancelot"); // almost forgot the ';' > > Try this in Python: > B.spin(myC, "Lancelot") > > > > Thanks, that was exactly the insight i needed. /Per -- Per Erik Strandberg blog: http://www.pererikstrandberg.se/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Re: ctypes and pointers
[This might be a double posting, if it isn't my previous post was lost] Look up "restype" in the ctypes library - it sets the return type from a function. You may want to set it to c_void_p of something similar, instead of the default int. I made a similar discovery in my blog - http://www.pererikstrandberg.se/blog/index.cgi?page=PythonCansiCombo . This example loads the function find_root from the dll root_find_lib.dll into the variable "find". the restype of find is then set to a c_double. This means that the item returned from C is a C_double and not the default int. root_find_lib = windll.LoadLibrary("root_find_lib.dll") find = root_find_lib.find_root find.restype = c_double You may already know this but 243666016 == 0E860C60 in different bases. HTH, Per [:)]-|--< -- Per Erik Strandberg .NET Architect - Optimization Tomlab Optimization Inc. http://tomopt.com/tomnet/ On 14 Apr, 19:25, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > Hi, > > I'm working under mac os x with the OpenCV-library that I load viactypes. > > From a ObjectiveC-methodcall I get an integer, that "really" is a > pointer to an IplImage-structure. > > I've got a function that takes such a pointer. But I don't find a way to > pass it to that very function. > > These are the relevant parts of my code: > > cvImage = self._f.cvImage() > print "Address of IplImage: %x" % cvImage > cvImage = c_void_p(cvImage) > print cvImage > cvImage2 = macopencv.cvCloneImage(cvImage) > > The output is > > 2007-04-14 19:22:53.910 SequenceGrabberTest[5320] Returning IplImage at > Address of IplImage: e860c60 > e860c60 > c_void_p(243666016) > 2007-04-14 19:22:53.915 SequenceGrabberTest[5320] Exception raised > during posting of notification. Ignored. exception: > exceptions.ValueError: depythonifying 'pointer', got 'int' > > The first line is actually from the ObjectivC-method, a log-statement. > > As one can see, the pointer is passed back as integer. > > But then I'm stuck. > > Any suggestions would be appreciated! > > diez -- http://mail.python.org/mailman/listinfo/python-list
annoying stdin/stdout + pipes problem
Hi, I want to create a program that reads input from stdio that can prompt a user for input while doing so without getting into problems. A simplified version of what I want: I have an input file ***>cat input.txt foo bar baz fubar barooba xyxxyt raboof txet black knight And a file that replaces certain words ***>cat replace2.py from sys import stdin, stdout def censor(foo, bar, input): return input.replace(foo, bar) # i = raw_input('Remove what? ').strip() # o = raw_input('Replace "%s" with what? ' %i).strip() for line in stdin.xreadlines(): line = censor('foo', 'candy', line) line = censor('bar', 'donkey', line) line = censor('baz', 'hare rama', line) # line = censor(i, o, line) stdout.write(line) ***>cat input.txt | python replace2.py candy donkey hare rama fudonkey donkeyooba xyxxyt raboof txet black knight As you can see I have commented out what I'd like to do but do not know how to. Can I somehow halt the previous print to stdout (cat input.txt) - if so can I then start it again, and how? I want to use this to use it in a small encryption program called txet in order to do something like this: tar -blabla ~ | gzip -blabla | txet -e -stdin -stdout > /tmp/ home.tar.gz.txet Of course I want to use it to get the password from the user. Thanks, Per PS: a prototype can be downloaded from www.txet.org -- http://mail.python.org/mailman/listinfo/python-list
Re: annoying stdin/stdout + pipes problem
On 23 Sep, 18:24, Damjan <[EMAIL PROTECTED]> wrote: > > I want to create a program that reads input from stdio that can prompt > > a user for input while doing so without getting into problems. > ... > > The trick (which works on Linux for sure) is to open /dev/tty and ask > question/get input on/from it. > ... > > I'm not usre for other *nix-es, and on Windows this will surelly not work > -- > damjan Thanks, it worked just fine on my Gnu/Linux machine, but I'd really like it to be independent of OS. Any one else got some idea - or a windows version of the same? /Per -- PS: for the record: ***>cat replace3.py && echo "---" && cat input.txt | python replace3.py from sys import stdin, stdout def censor(foo, bar, input): return input.replace(foo, bar) fp = open('/dev/tty', 'r+') fp.write('Remove what? ') i = fp.readline().strip() fp.write('Replace %s with what? ' %i) o = fp.readline().strip() fp.close() for line in stdin.xreadlines(): line = censor('foo', 'candy', line) line = censor('bar', 'donkey', line) line = censor('baz', 'hare rama', line) line = censor(i, o, line) stdout.write(line) --- Remove what? black Replace black with what? beige candy donkey hare rama fudonkey donkeyooba xyxxyt raboof txet beige knight -- http://mail.python.org/mailman/listinfo/python-list
Re: how to change sys.path?
also se topic named 'problem(s) with import from parent dir: "from ../brave.py import sir_robin" ' I use this every day now: sys.path.append("../../py_scripts") best wishes, Per -- http://mail.python.org/mailman/listinfo/python-list
Re: Counting number of each item in a list.
Dear counters, I have also encountered the above problem, and I frequently use the two blocks of code below. The first one is commented already - except that this version does not start from an empty dict. The second "inverts" the first one. Meaning that a dict in word2hits style: my_dict['the'] = 120 my_dict['word'] = 4 ... my_dict['gene'] = 4 becomes a dict in hits2words style: new_dict[4] = ['word','gene', ...] new_dict[120] = ['the', ...] I used these to count genes in in abstracts from pubmed the when I "invented" them (but it took some time to remove them from the code and use them as functions). def dict_add(indict,inlist,init=1): for item in inlist: if indict.has_key(item): indict[item] += 1 else: indict[item] = init return indict # end def def dict_invert(indict): new_dict = {} for key in indict.keys(): if new_dict.has_key(indict[key]): new_dict[indict[key]].append(key) else: new_dict[indict[key]] = [key] return new_dict #end def A good idea could be to change the header of the first one (if you want the option to start counting from zero) into: def dict_add(inlist,indict={},init=1): /P9K -- http://mail.python.org/mailman/listinfo/python-list
Re: Automated Graph Plotting in Python
Dear shrub-makers, if you are want to plot networks (fx. genetic networks) I can recommend Cytoscape: http://cytoscape.org/ (some kind of openware). The in-syntax is clean: node1 linktype1 node2 node2 linktype1 node3 node3 linktype2 node1 etc. But in general you are going to want to change the layout of the network after it is plotted. If you are into genetic networks it has a number of built-in stuff. (For 2D-plots (demand vs time) cytoscape is not an option.) I also recommend gnuplot (like everyone else) for making the standard y-axis, x-axis 2D-plots. It takes some time to learn syntax, but if I remember correctly it is pretty simple. /Per Then when you have found the shrubbery, you must cut down the mightiest tree in the forest...wth *pause* a herring! -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3.0 or Python 3000?
I can't wait to get my hands on version PAL9000, then we will all have to deallocate memory *the hard way*. /per9000 --- I'm afraid. I'm afraid, Dave. Dave, my mind is going. I can feel it. I can feel it. My mind is going. There is no question about it. I can feel it. I can feel it. I can feel it. I'm a ... fraid. --- -- http://mail.python.org/mailman/listinfo/python-list