Slurping All Content of a File into a Variable
Hi, How can we slurp content of a single file into one variable? I tried this: myfile_content = open('somefile.txt') print myfile_content, open file 'somefile.txt', mode 'r' at 0xb7f532e0 But it doesn't print the content of the file. Regards, -- Edward WIJAYA SINGAPORE Institute For Infocomm Research - Disclaimer - This email is confidential and may be privileged. If you are not the intended recipient, please delete it and notify us immediately. Please do not copy or use it for any purpose, or disclose its contents to any other person. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
RE: Slurping All Content of a File into a Variable Pls ignore, problem with mailing list, eom
From: [EMAIL PROTECTED] on behalf of Wijaya Edward Sent: Thu 10/26/2006 11:47 PM To: python-list@python.org Subject: Slurping All Content of a File into a Variable Hi, How can we slurp content of a single file into one variable? I tried this: myfile_content = open('somefile.txt') print myfile_content, open file 'somefile.txt', mode 'r' at 0xb7f532e0 But it doesn't print the content of the file. Regards, -- Edward WIJAYA SINGAPORE Institute For Infocomm Research - Disclaimer - This email is confidential and may be privileged. If you are not the intended recipient, please delete it and notify us immediately. Please do not copy or use it for any purpose, or disclose its contents to any other person. Thank you. -- http://mail.python.org/mailman/listinfo/python-list Institute For Infocomm Research - Disclaimer - This email is confidential and may be privileged. If you are not the intended recipient, please delete it and notify us immediately. Please do not copy or use it for any purpose, or disclose its contents to any other person. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Matching Pure Numeric and '' with Python re
Hi, Given this list: list = ['0123', '1A34' , '333-' , '' ] I want to match only this element '0123' (pure numeric) and '' (empty element). Why this construct doesn't work? p = re.compile(''+|[0-9]+) m = p.match(word) if m: print word, Namely it doesn't print 0123 and ''. What's wrong with my regex? -- Edward WIJAYA SINGAPORE Institute For Infocomm Research - Disclaimer - This email is confidential and may be privileged. If you are not the intended recipient, please delete it and notify us immediately. Please do not copy or use it for any purpose, or disclose its contents to any other person. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Problem Commenting within Filehandle Iteration
Hi all, I have the following code: import sys import re ham_count = 0 spam_count = 0 myfile = open('full/index') for line in myfile.readlines(): p = re.compile('ham') m = p.match(line) if m: print line, else: #print 'SPAM -- %s' % line myfile.close() Sometime while developing/debugging the code we usually put in such situation. Where expression under else is not yet supplied, yet we would like see the printout of the previous if condition. Notice that I wanted to comment out the #print line there. However I found problem with myfile.close(), with identation error. This error doesn't occur when commenting (#) is not in use. Why so? Is there away to do the commenting in correct way under this circumstances? -- Edward WIJAYA SINGAPORE Institute For Infocomm Research - Disclaimer - This email is confidential and may be privileged. If you are not the intended recipient, please delete it and notify us immediately. Please do not copy or use it for any purpose, or disclose its contents to any other person. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Printing Hidden Character in Python
Hi, How can we print out the hidden character like \n, \r etc in Python? -- Edward WIJAYA SINGAPORE Institute For Infocomm Research - Disclaimer - This email is confidential and may be privileged. If you are not the intended recipient, please delete it and notify us immediately. Please do not copy or use it for any purpose, or disclose its contents to any other person. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
RE: Printing Hidden Character in Python
Ben, I mean while opening a file, like this for line in open('somefile.txt'): print line printing line will not show the hidden chars like \n,\r. Is there a way to print it out? -- Edward WIJAYA SINGAPORE From: [EMAIL PROTECTED] on behalf of Ben Finney Sent: Thu 10/26/2006 4:59 PM To: python-list@python.org Subject: Re: Printing Hidden Character in Python Wijaya Edward [EMAIL PROTECTED] writes: How can we print out the hidden character like \n, \r etc in Python? What result do you want that you're not getting with: print \n -- \ Two rules to success in life: 1. Don't tell people everything | `\ you know. -- Sassan Tat | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list Institute For Infocomm Research - Disclaimer - This email is confidential and may be privileged. If you are not the intended recipient, please delete it and notify us immediately. Please do not copy or use it for any purpose, or disclose its contents to any other person. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Insert Content of a File into a Variable
Hi, How can we slurp all content of a single file into one variable? I tried this: myfile_content = open('somefile.txt') print myfile_content, open file 'somefile.txt', mode 'r' at 0xb7f532e0 But it doesn't print the content of the file. Regards, -- Edward WIJAYA SINGAPORE Institute For Infocomm Research - Disclaimer - This email is confidential and may be privileged. If you are not the intended recipient, please delete it and notify us immediately. Please do not copy or use it for any purpose, or disclose its contents to any other person. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
How to Split Chinese Character with backslash representation?
Hi all, I was trying to split a string that represent chinese characters below: str = '\xc5\xeb\xc7\xd5\xbc' print str2, ??? fields2 = split(r'\\',str) print fields2, ['\xc5\xeb\xc7\xd5\xbc'] But why the split function here doesn't seem to do the job for obtaining the desired result: ['\xc5','\xeb','\xc7','\xd5','\xbc'] Regards, -- Edward WIJAYA SINGAPORE Institute For Infocomm Research - Disclaimer - This email is confidential and may be privileged. If you are not the intended recipient, please delete it and notify us immediately. Please do not copy or use it for any purpose, or disclose its contents to any other person. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
RE: How to Split Chinese Character with backslash representation?
Thanks but my intention is to strictly use regex. Since there are separator I need to include as delimiter Especially for the case like this: str = '\xc5\xeb\xc7\xd5\xbc--FOO--BAR' field = list(str) print field ['\xc5', '\xeb', '\xc7', '\xd5', '\xbc', '-', '-', 'F', 'O', 'O', '-', '-', 'B', 'A', 'R'] What we want as the output is this instead: ['\xc5', '\xeb', '\xc7', '\xd5', '\xbc','FOO','BAR] What's the best way to do it? -- Edward WIJAYA SINGAPORE From: [EMAIL PROTECTED] on behalf of Cameron Walsh Sent: Fri 10/27/2006 12:03 PM To: python-list@python.org Subject: Re: How to Split Chinese Character with backslash representation? Wijaya Edward wrote: Hi all, I was trying to split a string that represent chinese characters below: str = '\xc5\xeb\xc7\xd5\xbc' print str2, ??? fields2 = split(r'\\',str) print fields2, ['\xc5\xeb\xc7\xd5\xbc'] But why the split function here doesn't seem to do the job for obtaining the desired result: ['\xc5','\xeb','\xc7','\xd5','\xbc'] Depends on what you want to do with them: string = '\xc5\xeb\xc7\xd5\xbc' for char in string: print char Å ë Ç Õ ¼ list_of_characters = list(string) list_of_characters ['\xc5', '\xeb', '\xc7', '\xd5', '\xbc'] for char in string: char '\xc5' '\xeb' '\xc7' '\xd5' '\xbc' for char in list_of_characters: print char Å ë Ç Õ ¼ string[3] '\xd5' string[1:3] '\xeb\xc7' Basically, you characters are already separated into a list of characters, that's effectively what a string is (but with a few more methods applicable only to lists of characters, not to other lists). -- http://mail.python.org/mailman/listinfo/python-list Institute For Infocomm Research - Disclaimer - This email is confidential and may be privileged. If you are not the intended recipient, please delete it and notify us immediately. Please do not copy or use it for any purpose, or disclose its contents to any other person. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Auto Completion for Python in VIM editor
Dear all, Perl and C/C++ have perl-support.vim and c.vim by Fritz Mehner that support a very convenient auto completion shortcut in visual mode (e.g \aw for While construct). Does anybody know if such a comprehensive scripts also exist for Python? python.vim doesn't seem to suppor this kind of autocompletion. Regards, Edward WIJAYA SINGAPORE Institute For Infocomm Research - Disclaimer - This email is confidential and may be privileged. If you are not the intended recipient, please delete it and notify us immediately. Please do not copy or use it for any purpose, or disclose its contents to any other person. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
RE: Where to find pydoc?
Hi, Can you be specific on which URLs can I find python-tools. Cause I tried the one under easy_install, I still can't find it. Thanks and hope to hear from you again. -- Edward WIJAYA SINGAPORE From: [EMAIL PROTECTED] on behalf of Fredrik Lundh Sent: Mon 10/16/2006 5:08 PM To: python-list@python.org Subject: Re: Where to find pydoc? look for python-tools or a similar package in your favourite package repository. /F -- http://mail.python.org/mailman/listinfo/python-list Institute For Infocomm Research - Disclaimer - This email is confidential and may be privileged. If you are not the intended recipient, please delete it and notify us immediately. Please do not copy or use it for any purpose, or disclose its contents to any other person. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Where to find pydoc?
I tried to call pydoc from my Linux box. To my realization that it doesn't contain pydoc. I thought this module should be a default module. Can anybody suggest where can I find the module? I tried: $ easy_install pydoc Searching for pydoc Reading http://sqlobject.org/ http://sqlobject.org/ Reading http://peak.telecommunity.com/dist http://peak.telecommunity.com/dist Reading http://www.python.org/pypi/pydoc/ http://www.python.org/pypi/pydoc/ Couldn't find index page for 'pydoc' (maybe misspelled?) Scanning index of all packages (this may take a while) Reading http://www.python.org/pypi/ http://www.python.org/pypi/ No local packages or download links found for pydoc error: Could not find suitable distribution for Requirement.parse('pydoc') Hope to hear from you again. Regards, Edward WIJAYA SINGAPORE Institute For Infocomm Research - Disclaimer - This email is confidential and may be privileged. If you are not the intended recipient, please delete it and notify us immediately. Please do not copy or use it for any purpose, or disclose its contents to any other person. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
RE: Where to find pydoc?
Hi, Thanks for the reply. Red Hat Linux Enterprise: Linux host.com 2.6.9-34.ELsmp #1 SMP Fri Feb 24 16:54:53 EST 2006 i686 i686 i386 GNU/Linux Python 2.3.4. Any problem with that? --- Edward From: [EMAIL PROTECTED] on behalf of Marc 'BlackJack' Rintsch Sent: Mon 10/16/2006 5:00 PM To: python-list@python.org Subject: Re: Where to find pydoc? In [EMAIL PROTECTED], Wijaya Edward wrote: I tried to call pydoc from my Linux box. To my realization that it doesn't contain pydoc. I thought this module should be a default module. Yes it is part of the standard library. What distribution are you using? Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list Institute For Infocomm Research - Disclaimer - This email is confidential and may be privileged. If you are not the intended recipient, please delete it and notify us immediately. Please do not copy or use it for any purpose, or disclose its contents to any other person. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Python Best Practice References
Can anybody suggest any references (links, books, etc)about this? I'm thinking of something similar with D.Conway's Perl Best Practice. -- Edward WIJAYA SINGAPORE Institute For Infocomm Research - Disclaimer - This email is confidential and may be privileged. If you are not the intended recipient, please delete it and notify us immediately. Please do not copy or use it for any purpose, or disclose its contents to any other person. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Loops Control with Python
Can we make loops control in Python? What I mean is that whether we can control which loops to exit/skip at the given scope. For example in Perl we can do something like: OUT: foreach my $s1 ( 0 ...100) { IN: foreach my $s2 (@array) { if ($s1 == $s2) { next OUT; } else { last IN; } } } How can we implement that construct with Python? -- Edward WIJAYA SINGAPORE Institute For Infocomm Research - Disclaimer - This email is confidential and may be privileged. If you are not the intended recipient, please delete it and notify us immediately. Please do not copy or use it for any purpose, or disclose its contents to any other person. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Click and Drag Functionality in Web Apps with Python
Hi, Some recent webapps like Kiko http://www.kiko.com/ , Google's gadget http://www.google.com/ig/directory?hl=en , and spreadsheets http://spreadsheets.google.com to name a few, have this functionality. I wonder how can this funcitonalities be implemented in Python. Do you guys have any experience with it? Any Python module that support that? Regards, Edward WIJAYA SINGAPOE Institute For Infocomm Research - Disclaimer - This email is confidential and may be privileged. If you are not the intended recipient, please delete it and notify us immediately. Please do not copy or use it for any purpose, or disclose its contents to any other person. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Hands on Documentation for Python methods and Library
Hi, One can do the following with Perl $ perldoc -f chomp $ perldoc -f function_name or $ perldoc List::MoreUtils $ perldoc Some::Module Can we do the same thing in Python? -- Edward SINGAPORE Institute For Infocomm Research - Disclaimer - This email is confidential and may be privileged. If you are not the intended recipient, please delete it and notify us immediately. Please do not copy or use it for any purpose, or disclose its contents to any other person. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Howto pass Array/Hash into Function
Hi, How can I pass Array, Hash, and a plain variable in to a function at the same time. I come from Perl. Where as you probably know it is done like this: sub myfunc { my ($plain_var, $hash_ref,$arref) = @_; # Do sth with those variables return; } I wonder how can that be done in Python. Regards, Edward WIJAYA SINGAPORE Institute For Infocomm Research - Disclaimer - This email is confidential and may be privileged. If you are not the intended recipient, please delete it and notify us immediately. Please do not copy or use it for any purpose, or disclose its contents to any other person. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
RE: Howto pass Array/Hash into Function
Thanks for your understanding Steve. Furthermore, my related concern is how does Python actually deal with 'reference' in Perl. But now, it is clear to me now that Python simply treats them as object. Regards, Edward WIJAYA SINGAPORE From: [EMAIL PROTECTED] on behalf of Steve Holden Sent: Tue 10/3/2006 8:08 PM To: python-list@python.org Subject: Re: Howto pass Array/Hash into Function It wouldn't be obvious to someone who learned Perl as their first programming language because Perl chose to ignore the otherwise almost universal convention that formal parameters determine the arguments that a function or procedure can be calles with. regards Steve Institute For Infocomm Research - Disclaimer - This email is confidential and may be privileged. If you are not the intended recipient, please delete it and notify us immediately. Please do not copy or use it for any purpose, or disclose its contents to any other person. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Benchmarking Python's subroutines/function
Hi, How does one benchmark multiple subroutines in Python? Is there a built-in library for that? -- Regards, Edward WIJAYA SINGAPORE Institute For Infocomm Research - Disclaimer - This email is confidential and may be privileged. If you are not the intended recipient, please delete it and notify us immediately. Please do not copy or use it for any purpose, or disclose its contents to any other person. Thank you. -- http://mail.python.org/mailman/listinfo/python-list