Re: [Tutor] Unittest
And in case: # coding: utf-8 import traceback try: raise Exception(u'Зрегиться') except Exception,e: print traceback.format_exc().decode('utf-8').encode('cp437', 'replace') Getting beryl:~ oleg$ python ./wish/newaccount/reg.py Traceback (most recent call last): File ./wish/newaccount/reg.py, line 5, in module raise Exception(u'?') Exception: unprintable Exception object My console settings: In [1]: import sys In [2]: sys.getdefaultencoding() Out[2]: 'ascii' In [3]: sys.stdout.encoding Out[3]: 'US-ASCII' On Thu, Jul 17, 2008 at 9:30 AM, Oleg Oltar [EMAIL PROTECTED] wrote: OK the output: # coding: utf-8 import traceback try: raise Exception(u'Зрегиться') except Exception,e: print traceback.format_exc().decode('utf-8') Traceback (most recent call last): File /var/folders/PC/PCtFE4gQGiqpQymiAScfnk+++TM/-Tmp-/py46506ECT, line 7, in module print traceback.format_exc().decode('utf-8') UnicodeEncodeError: 'ascii' codec can't encode characters in position 148-156: ordinal not in range(128) On Thu, Jul 17, 2008 at 8:13 AM, Mark Tolonen [EMAIL PROTECTED][EMAIL PROTECTED] wrote: The Exception is output in the encoding of the source file. If the terminal you are displaying the exception on is in a different encoding, it will be garbled. I'm not familiar with OS X's terminal. Try running python and printing sys.stdout.encoding. Alternatively, wrap your code in a try/except handler and translate the exception yourself. # coding: utf-8 import traceback try: raise Exception(u'Зарегистрироваться') except Exception,e: print traceback.format_exc().decode('utf-8') The last line translates the utf-8 traceback into Unicode. Printing Unicode will encode the output with the terminal's decoding. If there are characters it can't display, you'll still get an error, though. You can be more explicit however: print traceback.format_exc().decode('utf-8').encode('cp437','replace') In this case you'll get ? whenever a character can't be represented in the selected encoding. cp437, for example, can't display any russian characters, so for me (on Windows) I just get all ???. When I tried it with a character string that could be displayed in cp437, it worked fine: Traceback (most recent call last): File stdin, line 1, in module File t4.py, line 4, in module raise Exception('MàΓ£ΦΘΩδ') Exception: MàΓ£ΦΘΩδ Another option is to redirect the output to a file and read the file with an editor that can display utf-8 (such as Notepad on Windows). python testfile.py 2error.txt # this redirects stderr to a file. Hope that helps, Mark Oleg Oltar [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] The code # -*- coding: utf-8 -*- #!/usr/bin/python This test case check how system works in the situation, when user tries to use already used username (domain) We are creating two accounts with such parameters: 1. Sex = Femle 2. Name1=Name2 = foobar%S 3. Pass1 = Name 4. Pass2 = Name 5. Email address1 = Email address2 = [EMAIL PROTECTED] In the test we use verification point - warning message about incorrect input of domain name and the sugestion message from selenium import selenium import unittest, time, re import HTMLTestRunner import config import Creating_account_basic class Same_domain_name(unittest.TestCase): def setUp(self): self.name = foobar self.email = self.name + @meta.ua self.verificationErrors = [] self.selenium = selenium(localhost, ,config.browser, config.link) self.selenium.start() def test_create_account_to_check(self): Creating sample account for next test sel = self.selenium sel.open(/) sel.click(ulink=Регистрация) sel.wait_for_page_to_load(7) sel.click(id_gender_1) sel.type(id_first_name, self.name) sel.type(id_last_name, self.name) sel.type(id_email, self.email) sel.type(id_username, self.name) #sel.wait_for_condition(sel.is_element_present(check_username_block), 7) time.sleep(10) print !!!, sel.is_element_present(check_username_block) sel.type(id_password, self.name) print sel.get_text(check_username_block).decode('cp-1252') sel.type(id_password2, self.name) sel.click(u//[EMAIL PROTECTED]'Зарегистрироваться']) sel.wait_for_page_to_load(7) if config.debugMode is True: time.sleep(5) def tearDown(self): self.selenium.stop() print self.verificationErrors self.assertEqual([], self.verificationErrors) if __name__ == __main__: unittest.main() #HTMLTestRunner.main() On Thu, Jul 17, 2008 at 6:47 AM, Oleg Oltar [EMAIL PROTECTED] wrote: In [1]: import sys In [2]:
Re: [Tutor] Unittest
OK, your console is set to 'ascii' ('cp437' was my example and is the Windows console encoding). 'ascii' won't be able to display Russian. It shouldn't have displayed the Ð˜Ð·Ð²ÐµÐ½Ð¸Ñ characters either. Are you still running on the same terminal that display those characters? Can you change your terminals encoding preference via an environment variable? -- Mark Oleg Oltar [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] And in case: # coding: utf-8 import traceback try: raise Exception(u'Зрегиться') except Exception,e: print traceback.format_exc().decode('utf-8').encode('cp437', 'replace') Getting beryl:~ oleg$ python ./wish/newaccount/reg.py Traceback (most recent call last): File ./wish/newaccount/reg.py, line 5, in module raise Exception(u'?') Exception: unprintable Exception object My console settings: In [1]: import sys In [2]: sys.getdefaultencoding() Out[2]: 'ascii' In [3]: sys.stdout.encoding Out[3]: 'US-ASCII' On Thu, Jul 17, 2008 at 9:30 AM, Oleg Oltar [EMAIL PROTECTED] wrote: OK the output: # coding: utf-8 import traceback try: raise Exception(u'Зрегиться') except Exception,e: print traceback.format_exc().decode('utf-8') Traceback (most recent call last): File /var/folders/PC/PCtFE4gQGiqpQymiAScfnk+++TM/-Tmp-/py46506ECT, line 7, in module print traceback.format_exc().decode('utf-8') UnicodeEncodeError: 'ascii' codec can't encode characters in position 148-156: ordinal not in range(128) On Thu, Jul 17, 2008 at 8:13 AM, Mark Tolonen [EMAIL PROTECTED] wrote: The Exception is output in the encoding of the source file. If the terminal you are displaying the exception on is in a different encoding, it will be garbled. I'm not familiar with OS X's terminal. Try running python and printing sys.stdout.encoding. Alternatively, wrap your code in a try/except handler and translate the exception yourself. # coding: utf-8 import traceback try: raise Exception(u'Зарегистрироваться') except Exception,e: print traceback.format_exc().decode('utf-8') The last line translates the utf-8 traceback into Unicode. Printing Unicode will encode the output with the terminal's decoding. If there are characters it can't display, you'll still get an error, though. You can be more explicit however: print traceback.format_exc().decode('utf-8').encode('cp437','replace') In this case you'll get ? whenever a character can't be represented in the selected encoding. cp437, for example, can't display any russian characters, so for me (on Windows) I just get all ???. When I tried it with a character string that could be displayed in cp437, it worked fine: Traceback (most recent call last): File stdin, line 1, in module File t4.py, line 4, in module raise Exception('MàΓ£ΦΘΩδ') Exception: MàΓ£ΦΘΩδ Another option is to redirect the output to a file and read the file with an editor that can display utf-8 (such as Notepad on Windows). python testfile.py 2error.txt # this redirects stderr to a file. Hope that helps, Mark Oleg Oltar [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] The code # -*- coding: utf-8 -*- #!/usr/bin/python This test case check how system works in the situation, when user tries to use already used username (domain) We are creating two accounts with such parameters: 1. Sex = Femle 2. Name1=Name2 = foobar%S 3. Pass1 = Name 4. Pass2 = Name 5. Email address1 = Email address2 = [EMAIL PROTECTED] In the test we use verification point - warning message about incorrect input of domain name and the sugestion message from selenium import selenium import unittest, time, re import HTMLTestRunner import config import Creating_account_basic class Same_domain_name(unittest.TestCase): def setUp(self): self.name = foobar self.email = self.name + @meta.ua self.verificationErrors = [] self.selenium = selenium(localhost, ,config.browser, config.link) self.selenium.start() def test_create_account_to_check(self): Creating sample account for next test sel = self.selenium sel.open(/) sel.click(ulink=Регистрация) sel.wait_for_page_to_load(7) sel.click(id_gender_1) sel.type(id_first_name, self.name) sel.type(id_last_name, self.name)
Re: [Tutor] Unittest
Ok, seems it's my console setting. Tried console with koi8-r (from http://vak.ru/doku.php/macosx-russian), and it looks ok there. Mean the satndard output, but still getting D chars instead of russian when trying to convert it to html via HTMLTestRunner (see http://tungwaiyip.info/software/HTMLTestRunner.html) On Thu, Jul 17, 2008 at 9:33 AM, Oleg Oltar [EMAIL PROTECTED] wrote: And in case: # coding: utf-8 import traceback try: raise Exception(u'Зрегиться') except Exception,e: print traceback.format_exc().decode('utf-8').encode('cp437', 'replace') Getting beryl:~ oleg$ python ./wish/newaccount/reg.py Traceback (most recent call last): File ./wish/newaccount/reg.py, line 5, in module raise Exception(u'?') Exception: unprintable Exception object My console settings: In [1]: import sys In [2]: sys.getdefaultencoding() Out[2]: 'ascii' In [3]: sys.stdout.encoding Out[3]: 'US-ASCII' On Thu, Jul 17, 2008 at 9:30 AM, Oleg Oltar [EMAIL PROTECTED] wrote: OK the output: # coding: utf-8 import traceback try: raise Exception(u'Зрегиться') except Exception,e: print traceback.format_exc().decode('utf-8') Traceback (most recent call last): File /var/folders/PC/PCtFE4gQGiqpQymiAScfnk+++TM/-Tmp-/py46506ECT, line 7, in module print traceback.format_exc().decode('utf-8') UnicodeEncodeError: 'ascii' codec can't encode characters in position 148-156: ordinal not in range(128) On Thu, Jul 17, 2008 at 8:13 AM, Mark Tolonen [EMAIL PROTECTED][EMAIL PROTECTED] wrote: The Exception is output in the encoding of the source file. If the terminal you are displaying the exception on is in a different encoding, it will be garbled. I'm not familiar with OS X's terminal. Try running python and printing sys.stdout.encoding. Alternatively, wrap your code in a try/except handler and translate the exception yourself. # coding: utf-8 import traceback try: raise Exception(u'Зарегистрироваться') except Exception,e: print traceback.format_exc().decode('utf-8') The last line translates the utf-8 traceback into Unicode. Printing Unicode will encode the output with the terminal's decoding. If there are characters it can't display, you'll still get an error, though. You can be more explicit however: print traceback.format_exc().decode('utf-8').encode('cp437','replace') In this case you'll get ? whenever a character can't be represented in the selected encoding. cp437, for example, can't display any russian characters, so for me (on Windows) I just get all ???. When I tried it with a character string that could be displayed in cp437, it worked fine: Traceback (most recent call last): File stdin, line 1, in module File t4.py, line 4, in module raise Exception('MàΓ£ΦΘΩδ') Exception: MàΓ£ΦΘΩδ Another option is to redirect the output to a file and read the file with an editor that can display utf-8 (such as Notepad on Windows). python testfile.py 2error.txt # this redirects stderr to a file. Hope that helps, Mark Oleg Oltar [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] The code # -*- coding: utf-8 -*- #!/usr/bin/python This test case check how system works in the situation, when user tries to use already used username (domain) We are creating two accounts with such parameters: 1. Sex = Femle 2. Name1=Name2 = foobar%S 3. Pass1 = Name 4. Pass2 = Name 5. Email address1 = Email address2 = [EMAIL PROTECTED] In the test we use verification point - warning message about incorrect input of domain name and the sugestion message from selenium import selenium import unittest, time, re import HTMLTestRunner import config import Creating_account_basic class Same_domain_name(unittest.TestCase): def setUp(self): self.name = foobar self.email = self.name + @meta.ua self.verificationErrors = [] self.selenium = selenium(localhost, ,config.browser, config.link) self.selenium.start() def test_create_account_to_check(self): Creating sample account for next test sel = self.selenium sel.open(/) sel.click(ulink=Регистрация) sel.wait_for_page_to_load(7) sel.click(id_gender_1) sel.type(id_first_name, self.name) sel.type(id_last_name, self.name) sel.type(id_email, self.email) sel.type(id_username, self.name) #sel.wait_for_condition(sel.is_element_present(check_username_block), 7) time.sleep(10) print !!!, sel.is_element_present(check_username_block) sel.type(id_password, self.name) print sel.get_text(check_username_block).decode('cp-1252') sel.type(id_password2, self.name) sel.click(u//[EMAIL PROTECTED]'Зарегистрироваться']) sel.wait_for_page_to_load(7) if
Re: [Tutor] Does IPython have a restart?
At 07:55 AM 7/16/2008, Dick Moores wrote: I mean something equivalent to what you get when you do a Ctrl+F6 in IDLE: import math math.log(3) 1.0986122886681098 === RESTART === math.log(3) Traceback (most recent call last): File pyshell#9, line 1, in module math.log(3) NameError: name 'math' is not defined === Got this from the ipython-user list: Use %reset: In [1]: import math In [2]: math.sin(3) Out[2]: 0.14112000805986721 In [3]: %reset Once deleted, variables cannot be recovered. Proceed (y/[n])? y In [5]: math.sin(3) --- NameError Traceback (most recent call last) /home/fperez/Desktop/ipython console in module() NameError: name 'math' is not defined Note that it is NOT the same though: idle forces a new, fresh python process, while ipython just clears your current variables. So things like reloading extension modules won't work the same way. Dick ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Unittest
You get the D characters when decoding Russian encoded in UTF-8 using Latin-1 instead. # coding: utf-8 x=u'Зарегистрироваться' print x.encode('utf-8').decode('latin-1') ÐаÑегиÑÑÑиÑоваÑÑÑÑ Check that your html encoding is declared correctly. -- Mark Oleg Oltar [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Ok, seems it's my console setting. Tried console with koi8-r (from http://vak.ru/doku.php/macosx-russian), and it looks ok there. Mean the satndard output, but still getting D chars instead of russian when trying to convert it to html via HTMLTestRunner (see http://tungwaiyip.info/software/HTMLTestRunner.html) On Thu, Jul 17, 2008 at 9:33 AM, Oleg Oltar [EMAIL PROTECTED] wrote: And in case: # coding: utf-8 import traceback try: raise Exception(u'Зрегиться') except Exception,e: print traceback.format_exc().decode('utf-8').encode('cp437', 'replace') Getting beryl:~ oleg$ python ./wish/newaccount/reg.py Traceback (most recent call last): File ./wish/newaccount/reg.py, line 5, in module raise Exception(u'?') Exception: unprintable Exception object My console settings: In [1]: import sys In [2]: sys.getdefaultencoding() Out[2]: 'ascii' In [3]: sys.stdout.encoding Out[3]: 'US-ASCII' On Thu, Jul 17, 2008 at 9:30 AM, Oleg Oltar [EMAIL PROTECTED] wrote: OK the output: # coding: utf-8 import traceback try: raise Exception(u'Зрегиться') except Exception,e: print traceback.format_exc().decode('utf-8') Traceback (most recent call last): File /var/folders/PC/PCtFE4gQGiqpQymiAScfnk+++TM/-Tmp-/py46506ECT, line 7, in module print traceback.format_exc().decode('utf-8') UnicodeEncodeError: 'ascii' codec can't encode characters in position 148-156: ordinal not in range(128) On Thu, Jul 17, 2008 at 8:13 AM, Mark Tolonen [EMAIL PROTECTED] wrote: The Exception is output in the encoding of the source file. If the terminal you are displaying the exception on is in a different encoding, it will be garbled. I'm not familiar with OS X's terminal. Try running python and printing sys.stdout.encoding. Alternatively, wrap your code in a try/except handler and translate the exception yourself. # coding: utf-8 import traceback try: raise Exception(u'Зарегистрироваться') except Exception,e: print traceback.format_exc().decode('utf-8') The last line translates the utf-8 traceback into Unicode. Printing Unicode will encode the output with the terminal's decoding. If there are characters it can't display, you'll still get an error, though. You can be more explicit however: print traceback.format_exc().decode('utf-8').encode('cp437','replace') In this case you'll get ? whenever a character can't be represented in the selected encoding. cp437, for example, can't display any russian characters, so for me (on Windows) I just get all ???. When I tried it with a character string that could be displayed in cp437, it worked fine: Traceback (most recent call last): File stdin, line 1, in module File t4.py, line 4, in module raise Exception('MàΓ£ΦΘΩδ') Exception: MàΓ£ΦΘΩδ Another option is to redirect the output to a file and read the file with an editor that can display utf-8 (such as Notepad on Windows). python testfile.py 2error.txt # this redirects stderr to a file. Hope that helps, Mark Oleg Oltar [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] The code # -*- coding: utf-8 -*- #!/usr/bin/python This test case check how system works in the situation, when user tries to use already used username (domain) We are creating two accounts with such parameters: 1. Sex = Femle 2. Name1=Name2 = foobar%S 3. Pass1 = Name 4. Pass2 = Name 5. Email address1 = Email address2 = [EMAIL PROTECTED] In the test we use verification point - warning message about incorrect input of domain name and the sugestion message from selenium import selenium import unittest, time, re import HTMLTestRunner import config import Creating_account_basic class Same_domain_name(unittest.TestCase): def setUp(self): self.name = foobar self.email = self.name + @meta.ua self.verificationErrors = [] self.selenium = selenium(localhost, ,config.browser,
Re: [Tutor] Any way of monitoring a python program's memory utilization?
I'm iterating through a vey large tarfile (uncompressed, it would be about 2.4G, with about 2.5 million files in it) and I can see from some external monitors that its virtual storage usage just grows and grows, until my whole system finally grinds to a halt after about 1.2 million members have been processed. Well, you can check whether your system has reached its limits or not, but what for ? it will lead you no where as the only sthing you can do is stop your program (while MEM_stat = 1G: parse(); else: break) you don't get anything done. I believe installing more memroy in your system is the way to go, you need to have at least 3G of Memory (memory is cheap these days), then don't let python use it as you don't know how much memory it will need for your program's internal routines, but create a virtual drive in memory (RAM DRIVE) extract the tar file into it parse its content as you wish (ofcourse you can use harddrive too ut its gona be VERY slow (specialy on Windows)). ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Any way of monitoring a python program's memory utilization?
On Thu, 17 Jul 2008, Monika Jisswel wrote: Well, you can check whether your system has reached its limits or not, but what for ? So I can debug the problem. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] IPython problem: Difficulty in setting editor to TextPad
Win XP, Python 2.51, IPython 0.84 In my ipy_user_conf.py I have put this line: ipy_editors.install_editor(C:\Program Files\TextPad 5\TextPad.exe) I use IPython -debug to start IPython, and this is what it tells me: 'editor': 'C:\\Program Files\\TextPad 5\\textpad.exe', but In [3]: ed versions.py Editing... C:\Program Files\TextPad 5\TextPad.exe 'C:\Program' is not recognized as an internal or external command, operable program or batch file. done. Executing edited code... [snip] It seems obvious that there still is a problem with the spaces in the path, but I don't know what to do about them. Help, please. Dick Moores Have you seen the video introducing the terrific and free IDE, Ulipad? Download it from my website. http://www.rcblue.com/u3/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Unittest
beryl:~ oleg$ env MANPATH=/usr/share/man:/usr/local/share/man:/usr/X11/man TERM_PROGRAM=Apple_Terminal TERM=xterm-color SHELL=/bin/bash TMPDIR=/var/folders/PC/PCtFE4gQGiqpQymiAScfnk+++TM/-Tmp-/ Apple_PubSub_Socket_Render=/tmp/launch-UNXiC6/Render TERM_PROGRAM_VERSION=237 USER=oleg COMMAND_MODE=unix2003 SSH_AUTH_SOCK=/tmp/launch-hfpsIl/Listeners __CF_USER_TEXT_ENCODING=0x1F6:0:0 PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin PWD=/Users/oleg LANG=ru_RU.UTF-8 SHLVL=1 HOME=/Users/oleg PYTHONPATH=:/Users/oleg/Documents/wishes_Test LOGNAME=oleg DISPLAY=/tmp/launch-1kgALC/:0 SECURITYSESSIONID=a206d0 On Thu, Jul 17, 2008 at 9:58 AM, Oleg Oltar [EMAIL PROTECTED] wrote: See previous message (sent it few seconds ago) On Thu, Jul 17, 2008 at 9:55 AM, Mark Tolonen [EMAIL PROTECTED][EMAIL PROTECTED] wrote: OK, your console is set to 'ascii' ('cp437' was my example and is the Windows console encoding). 'ascii' won't be able to display Russian. It shouldn't have displayed the Ð˜Ð·Ð²ÐµÐ½Ð¸Ñ characters either. Are you still running on the same terminal that display those characters? Can you change your terminals encoding preference via an environment variable? -- Mark Oleg Oltar [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] And in case: # coding: utf-8 import traceback try: raise Exception(u'Зрегиться') except Exception,e: print traceback.format_exc().decode('utf-8').encode('cp437', 'replace') Getting beryl:~ oleg$ python ./wish/newaccount/reg.py Traceback (most recent call last): File ./wish/newaccount/reg.py, line 5, in module raise Exception(u'?') Exception: unprintable Exception object My console settings: In [1]: import sys In [2]: sys.getdefaultencoding() Out[2]: 'ascii' In [3]: sys.stdout.encoding Out[3]: 'US-ASCII' On Thu, Jul 17, 2008 at 9:30 AM, Oleg Oltar [EMAIL PROTECTED] wrote: OK the output: # coding: utf-8 import traceback try: raise Exception(u'Зрегиться') except Exception,e: print traceback.format_exc().decode('utf-8') Traceback (most recent call last): File /var/folders/PC/PCtFE4gQGiqpQymiAScfnk+++TM/-Tmp-/py46506ECT, line 7, in module print traceback.format_exc().decode('utf-8') UnicodeEncodeError: 'ascii' codec can't encode characters in position 148-156: ordinal not in range(128) On Thu, Jul 17, 2008 at 8:13 AM, Mark Tolonen [EMAIL PROTECTED][EMAIL PROTECTED] wrote: The Exception is output in the encoding of the source file. If the terminal you are displaying the exception on is in a different encoding, it will be garbled. I'm not familiar with OS X's terminal. Try running python and printing sys.stdout.encoding. Alternatively, wrap your code in a try/except handler and translate the exception yourself. # coding: utf-8 import traceback try: raise Exception(u'Зарегистрироваться') except Exception,e: print traceback.format_exc().decode('utf-8') The last line translates the utf-8 traceback into Unicode. Printing Unicode will encode the output with the terminal's decoding. If there are characters it can't display, you'll still get an error, though. You can be more explicit however: print traceback.format_exc().decode('utf-8').encode('cp437','replace') In this case you'll get ? whenever a character can't be represented in the selected encoding. cp437, for example, can't display any russian characters, so for me (on Windows) I just get all ???. When I tried it with a character string that could be displayed in cp437, it worked fine: Traceback (most recent call last): File stdin, line 1, in module File t4.py, line 4, in module raise Exception('MàΓ£ΦΘΩδ') Exception: MàΓ£ΦΘΩδ Another option is to redirect the output to a file and read the file with an editor that can display utf-8 (such as Notepad on Windows). python testfile.py 2error.txt # this redirects stderr to a file. Hope that helps, Mark Oleg Oltar [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] The code # -*- coding: utf-8 -*- #!/usr/bin/python This test case check how system works in the situation, when user tries to use already used username (domain) We are creating two accounts with such parameters: 1. Sex = Femle 2. Name1=Name2 = foobar%S 3. Pass1 = Name 4. Pass2 = Name 5. Email address1 = Email address2 = [EMAIL PROTECTED] In the test we use verification point - warning message about incorrect input of domain name and the sugestion message from selenium import selenium import unittest, time, re import HTMLTestRunner import config import Creating_account_basic class Same_domain_name(unittest.TestCase): def setUp(self): self.name = foobar self.email = self.name + @meta.ua self.verificationErrors = [] self.selenium = selenium(localhost, ,config.browser,
Re: [Tutor] Unittest
And also: Getting this in console when trying to generate report via HTMLTestRunner (it displayed text correctly when tried simple unittest.main) td colspan='5' align='center'a href=javascript:showOutput('pt1.1', 'test_create_account_to_check: Creating sample account for next test')pass/a script language=javascript type=text/javascriptoutput_list['pt1.1'] = '!!! True\nÐомен \'foobar\' занÑÑ. РекомендованнÑе ÑвободнÑе доменÑ: ffoobar foobar.foobar foofoo fofo\n[]\n';/script /td /tr On Thu, Jul 17, 2008 at 10:01 AM, Oleg Oltar [EMAIL PROTECTED] wrote: beryl:~ oleg$ env MANPATH=/usr/share/man:/usr/local/share/man:/usr/X11/man TERM_PROGRAM=Apple_Terminal TERM=xterm-color SHELL=/bin/bash TMPDIR=/var/folders/PC/PCtFE4gQGiqpQymiAScfnk+++TM/-Tmp-/ Apple_PubSub_Socket_Render=/tmp/launch-UNXiC6/Render TERM_PROGRAM_VERSION=237 USER=oleg COMMAND_MODE=unix2003 SSH_AUTH_SOCK=/tmp/launch-hfpsIl/Listeners __CF_USER_TEXT_ENCODING=0x1F6:0:0 PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin PWD=/Users/oleg LANG=ru_RU.UTF-8 SHLVL=1 HOME=/Users/oleg PYTHONPATH=:/Users/oleg/Documents/wishes_Test LOGNAME=oleg DISPLAY=/tmp/launch-1kgALC/:0 SECURITYSESSIONID=a206d0 On Thu, Jul 17, 2008 at 9:58 AM, Oleg Oltar [EMAIL PROTECTED] wrote: See previous message (sent it few seconds ago) On Thu, Jul 17, 2008 at 9:55 AM, Mark Tolonen [EMAIL PROTECTED][EMAIL PROTECTED] wrote: OK, your console is set to 'ascii' ('cp437' was my example and is the Windows console encoding). 'ascii' won't be able to display Russian. It shouldn't have displayed the Ð˜Ð·Ð²ÐµÐ½Ð¸Ñ characters either. Are you still running on the same terminal that display those characters? Can you change your terminals encoding preference via an environment variable? -- Mark Oleg Oltar [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] And in case: # coding: utf-8 import traceback try: raise Exception(u'Зрегиться') except Exception,e: print traceback.format_exc().decode('utf-8').encode('cp437', 'replace') Getting beryl:~ oleg$ python ./wish/newaccount/reg.py Traceback (most recent call last): File ./wish/newaccount/reg.py, line 5, in module raise Exception(u'?') Exception: unprintable Exception object My console settings: In [1]: import sys In [2]: sys.getdefaultencoding() Out[2]: 'ascii' In [3]: sys.stdout.encoding Out[3]: 'US-ASCII' On Thu, Jul 17, 2008 at 9:30 AM, Oleg Oltar [EMAIL PROTECTED] wrote: OK the output: # coding: utf-8 import traceback try: raise Exception(u'Зрегиться') except Exception,e: print traceback.format_exc().decode('utf-8') Traceback (most recent call last): File /var/folders/PC/PCtFE4gQGiqpQymiAScfnk+++TM/-Tmp-/py46506ECT, line 7, in module print traceback.format_exc().decode('utf-8') UnicodeEncodeError: 'ascii' codec can't encode characters in position 148-156: ordinal not in range(128) On Thu, Jul 17, 2008 at 8:13 AM, Mark Tolonen [EMAIL PROTECTED][EMAIL PROTECTED] wrote: The Exception is output in the encoding of the source file. If the terminal you are displaying the exception on is in a different encoding, it will be garbled. I'm not familiar with OS X's terminal. Try running python and printing sys.stdout.encoding. Alternatively, wrap your code in a try/except handler and translate the exception yourself. # coding: utf-8 import traceback try: raise Exception(u'Зарегистрироваться') except Exception,e: print traceback.format_exc().decode('utf-8') The last line translates the utf-8 traceback into Unicode. Printing Unicode will encode the output with the terminal's decoding. If there are characters it can't display, you'll still get an error, though. You can be more explicit however: print traceback.format_exc().decode('utf-8').encode('cp437','replace') In this case you'll get ? whenever a character can't be represented in the selected encoding. cp437, for example, can't display any russian characters, so for me (on Windows) I just get all ???. When I tried it with a character string that could be displayed in cp437, it worked fine: Traceback (most recent call last): File stdin, line 1, in module File t4.py, line 4, in module raise Exception('MàΓ£ΦΘΩδ') Exception: MàΓ£ΦΘΩδ Another option is to redirect the output to a file and read the file with an editor that can display utf-8 (such as Notepad on Windows). python testfile.py 2error.txt # this redirects stderr to a file. Hope that helps, Mark Oleg Oltar [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] The code # -*- coding: utf-8 -*- #!/usr/bin/python This test case check how system works in the situation, when user tries to use already used username (domain) We are creating two accounts with such parameters: 1. Sex =
Re: [Tutor] Any way of monitoring a python program's memory utilization?
I see no problem, if you open very BIG files then your memory will get filled up your system will halt, can you buy more food than your fridge can handle , and write to a list asking to invistigate the problem ? 2008/7/17 Terry Carroll [EMAIL PROTECTED]: On Thu, 17 Jul 2008, Monika Jisswel wrote: Well, you can check whether your system has reached its limits or not, but what for ? So I can debug the problem. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] How to populate a dictionary
Hello, I am taking python this summer, and have run into a problem. The assignment is to create a dictionary from a text file: 12/07/0526 = St Felix IV begins his reign as Catholic Pope 12/07/1109 = Crusaders capture Syria's harbor city of Tripoli 12/07/1191 = Richard Coeur de Lion and Crusaders defeat Saracens in Palestine 12/07/1290 = Jews are expelled from England by order of King Edward I 12/07/1442 = King Alfonso V of Arag¢n becomes king of Naples Create a dictionary of dates. Each date you have in there should have a special event. An example would be that the dictionary would contain the following NOTE: You must have at least 100 different dates. You can get this from lists on the internet if you like, but it must be something real, not just garbage or something just made up. 12/28/1929: My Birthday 1/1/1948: New Years Day 48 9/11: the big one Your program should start by creating an empty dictionary called dates. Then your program will get an array of ALL the keys for that dictionary and then write a loop that will display all the key/value pairs. BUT: The dictionary setup file should exist OUTSIDE of the program, you should have lines in it that say something like 12/28/1948=Starting Day or something like that. Your strategy will be to open that file, read it, split it into lines, then for each line, you will split that line by the equals = sign. The left side value is the Key and the Right Hand Side is the value. You will read this whole files, splitting each key/value pair and store them in a dictionary. Then write the loop which will get all the keys, SORT those keys and print out the key/value pairs. here is a sample of my code: #!python myDictionary = { } inputLines = open (dates.txt) .read() .split (\n) for i in range ( len(inputLines) ) : if (inputLines [i] != ) : leftHandSide = inputLines [i].split (=) rightHandSide = inputLines [i].split (=) myDictionary [leftHandSide] = rightHandSide theKeys = myDictionary.keys () theKeys.sort () for i in range (len (theKeys) ): print theKeys[i], myDictionary[ theKeys[i] ] Can anyone help? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Recursive function
hi all, i am new to programming, i just started writing scripts in python about functions.There is a program by name hangman where in i take input three characters and then concatenate the resultant output is compared to a three letter string, if it is similar it will display the word as correct if not i want to execute the same function which evokes to prompt for three characters as input. The problem is i am not getting a runtime error. below is the piece of code: #word Hangman print Welcome to the Hangman print print a = raw_input(enter 1st letter=) b = raw_input(enter 2nd letter=) c = raw_input(enter 3rd letter=) def cmp(): d = (a+b+c); if (d=='PAN'): print word 'd' is correct else: print Try Again CALL(); def CALL(): cmp(); cmp() -- Raghavendra Vanam ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to populate a dictionary
josetjr wrote... Hello, I am taking python this summer, and have run into a problem. Let me suggest some improvements. You can process all the lines in a textfile like this: for line in open(dates.txt).readlines(): print line Furthermore, if you have a string in the form of ABC=DEF, you can split it like this: key,value=s.split(=) To enumerate the keys of a dictionary in alphabetical order, you can use: for k in sorted(d): print k So, your little homework program becomes more pythonic like this: history={} for line in open(dates.txt).readlines(): line=line.strip(\n\) # clean the line a bit; strip off the newline and quotes date,event=line.split(=) history[date]=event for k in sorted(history): print k,history[k] Have a nice day, -- The ability of the OSS process to collect and harness the collective IQ of thousands of individuals across the Internet is simply amazing. - Vinod Vallopillil http://www.catb.org/~esr/halloween/halloween4.html ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to populate a dictionary
Dates = {} def read_Dates (Dates): if os.path.exists(FILE_NAME): store = open(FILE_NAME,'r') for line in store: name = line.rstrip() entry = store.next().rstrip() Dates[name] = entry store.close() def save_Dates (Dates): store = open(FILE_NAME, 'w') for name,entry in Dates.items(): store.write(name + '\n') store.write(entry + '\n') store.close() print %s File Saved and Closed! % FILE_NAME - Original Message - From: [EMAIL PROTECTED] To: tutor@python.org Sent: Thursday, July 17, 2008 8:07 AM Subject: [Tutor] How to populate a dictionary Hello, I am taking python this summer, and have run into a problem. The assignment is to create a dictionary from a text file: 12/07/0526 = St Felix IV begins his reign as Catholic Pope 12/07/1109 = Crusaders capture Syria's harbor city of Tripoli 12/07/1191 = Richard Coeur de Lion and Crusaders defeat Saracens in Palestine 12/07/1290 = Jews are expelled from England by order of King Edward I 12/07/1442 = King Alfonso V of Arag¢n becomes king of Naples Create a dictionary of dates. Each date you have in there should have a special event. An example would be that the dictionary would contain the following NOTE: You must have at least 100 different dates. You can get this from lists on the internet if you like, but it must be something real, not just garbage or something just made up. 12/28/1929: My Birthday 1/1/1948: New Years Day 48 9/11: the big one Your program should start by creating an empty dictionary called dates. Then your program will get an array of ALL the keys for that dictionary and then write a loop that will display all the key/value pairs. BUT: The dictionary setup file should exist OUTSIDE of the program, you should have lines in it that say something like 12/28/1948=Starting Day or something like that. Your strategy will be to open that file, read it, split it into lines, then for each line, you will split that line by the equals = sign. The left side value is the Key and the Right Hand Side is the value. You will read this whole files, splitting each key/value pair and store them in a dictionary. Then write the loop which will get all the keys, SORT those keys and print out the key/value pairs. here is a sample of my code: #!python myDictionary = { } inputLines = open (dates.txt) .read() .split (\n) for i in range ( len(inputLines) ) : if (inputLines [i] != ) : leftHandSide = inputLines [i].split (=) rightHandSide = inputLines [i].split (=) myDictionary [leftHandSide] = rightHandSide theKeys = myDictionary.keys () theKeys.sort () for i in range (len (theKeys) ): print theKeys[i], myDictionary[ theKeys[i] ] Can anyone help? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor No virus found in this incoming message. Checked by AVG. Version: 7.5.524 / Virus Database: 270.5.0/1557 - Release Date: 7/17/2008 5:36 AM ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to populate a dictionary
Several reactions: --- As I understood it the list policy is: 1) not solve homework problems. 2) request students to tell us exactly what problems they were running into e.g. expected output, actual output, exceptions, ... 3) then give specific suggestions We seem to have violated that policy in this case. Can we in agreement on the policy? --- I also prefer list posts to be in plain text rather than various fonts, sizes and colors. --- I think that assignment is very poorly worded! Why the busywork of coming up with 100 real dates. What does that have to do with programming? -- Bob Gailer 919-636-4239 Chapel Hill, NC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Any way of monitoring a python program's memoryutilization?
Monika Jisswel [EMAIL PROTECTED] wrote... I see no problem, if you open very BIG files then your memory will get filled up your system will halt, Only if you were to foolishly read the whole file into memory at once. Early computers only had memories of a few kilobytes but could process files much larger than that - I recall using one with only 16K RAM and no hard drive( a server not a home computer) that was able to process data files of several megabytes. And many PC databases are 10's of GB in size and a database is no more than a few very big files. Given that many PCs have a hardware upper memory limit of 2G and 32bit processors a limit of 4G that would make life very difficult if we were restricted in file size by the RAM available. You just have to make sure you read the files in small chunks. and process each chunk in turn. (A technique usually referred to as paging.) In python the chunk size is usually a line... There is only a problem if you try saving all of the lines into a collection of some sort So I can debug the problem. The problem he is trying to debug is why the files are using up his memory when he (presumably) was not expecting them to fill it. To use the fridge analogy, why is the fridge still full after I've eaten all the food? Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to populate a dictionary
[EMAIL PROTECTED] wrote The assignment is to create a dictionary from a text file: ok, since it's 'homework' I won't give the whole answer but will try to point you in the right direction. Your program should start by creating an empty dictionary called dates. Then your program will get an array of ALL the keys for that dictionary and then write a loop that will display all the key/value pairs. OK, I'm not sure why they want you to build an array, its not really necessary... you should have lines in it that say something like 12/28/1948=Starting Day open that file, read it, split it into lines, then for each line, Again you don;t need to do all of that, Python has a function readlines() that does it all for you. you will split that line by the equals = sign. The left side value is the Key and the Right Hand Side is the value. You will read this whole files, splitting each key/value pair and store them in a dictionary. You can do this one line at a time rather than reading the file then going back over it to split/store the data. Then write the loop which will get all the keys, SORT those keys and print out the key/value pairs. OK, Again thats a bit off track as a sequence. I'd get the keys, sort them then write a loop over the sorted keys to display the results. myDictionary = { } #AG-You were asked to call it dates! inputLines = open (dates.txt) .read() .split (\n) for i in range ( len(inputLines) ) : Could just be: for line in open(dates.txt): if (inputLines [i] != ) : leftHandSide = inputLines [i].split (=) rightHandSide = inputLines [i].split (=) These two lines do the same split. You need to store the first split value in one variable and the second in the other. (Remember split() returns a list). Try: lhs, rhs = line.split('=') myDictionary [leftHandSide] = rightHandSide theKeys = myDictionary.keys () theKeys.sort () for i in range (len (theKeys) ): print theKeys[i], myDictionary[ theKeys[i] ] Rather than indexing via range(len()), a Python for loop is best used to get the items directly. Thus: for key in theKeys: print key, dates[key] See how much more readable it is? And how much less typing! If you have a recent version of Python you can also avoid the business of extracting the keys and sorting them by using the sorted() function on the dates directly as part of the for loop. I'll leave that as an extra research topic! :-) HTH, -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to populate a dictionary
bob gailer [EMAIL PROTECTED] wrote As I understood it the list policy is: 1) not solve homework problems. 2) request students to tell us exactly what problems they were running into e.g. expected output, actual output, exceptions, ... 3) then give specific suggestions We seem to have violated that policy in this case. Can we in agreement on the policy? So far as I know the policy remains as it always was Bob. I also prefer list posts to be in plain text rather than various fonts, sizes and colors. I haven't had that problem. They are all in plain text whenI get them, but thats probably my mail/news reader settings I think that assignment is very poorly worded! I agree, the recommended sequence to solve is not great, but it's better than some homework assignments I've seen posted here. Why the busywork of coming up with 100 real dates. What does that have to do with programming? Agreed, thats just silly. Unless the course is also trying to teach research skills! Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] IPython problem: Difficulty in setting editor to TextPad
Dick Moores [EMAIL PROTECTED] wrote In my ipy_user_conf.py I have put this line: ipy_editors.install_editor(C:\Program Files\TextPad 5\TextPad.exe) escape the spaces and backslashes(raw string might work as well) ipy_editors.install_editor(C:\\Program\ Files\\TextPad 5\\TextPad.exe) OR maybe ipy_editors.install_editor(rC:\Program Files\TextPad 5\TextPad.exe) Alan G ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] IPython problem: Difficulty in setting editor to TextPad
At 08:13 AM 7/17/2008, Alan Gauld wrote: Dick Moores [EMAIL PROTECTED] wrote In my ipy_user_conf.py I have put this line: ipy_editors.install_editor(C:\Program Files\TextPad 5\TextPad.exe) escape the spaces and backslashes(raw string might work as well) Yeah, I tried that (except for the raw string). ipy_editors.install_editor(C:\\Program\ Files\\TextPad 5\\TextPad.exe) OR maybe ipy_editors.install_editor(rC:\Program Files\TextPad 5\TextPad.exe) I finally got some help from one of the main IPython guys (just now). The line that partially works is ipy_editors.install_editor('C:\Program Files\TextPad 5\TextPad.exe ${file}(${line})') But using the line number doesn't work, so I skip it and do In [3]: ed versions.py Editing... C:\Program Files\TextPad 5\TextPad.exe versions.py(0) This DOES open versions.py in Textpad, with the caret at line 1. Thanks for your educated guesses, Alan. Dick == Have you seen the video introducing the terrific and free IDE, Ulipad? Download it from my website. http://www.rcblue.com/u3/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Recursive function
vanam [EMAIL PROTECTED] wrote i am new to programming, i just started writing scripts in python about functions. You need to check the section of your tutorial/book that discusses loops. That will make your solution much easier. characters as input. The problem is i am not getting a runtime error. Tell us what you are getting (and what you expected), it makes our job easier if we don't have to guess. below is the piece of code: #word Hangman print Welcome to the Hangman print print a = raw_input(enter 1st letter=) b = raw_input(enter 2nd letter=) c = raw_input(enter 3rd letter=) def cmp(): You shouldn't write functions with the same name as builtin functions. You will not be able to use the builtin one if you do! cmp() is the builtin Python function for comparing two things. d = (a+b+c); You could just have read the three letters at once using raw_input... if (d=='PAN'): print word 'd' is correct else: print Try Again CALL(); def CALL(): cmp(); You don;t need CALL, you could just have called cmp from inside cmp - this is known as a recursice call and is allowed in Python. It can be used to create a loop effect here as you do but it has a limited number of repetitions and is best not used for that purpose. Instead use the built in looping constructs in Python for or while In your case you probabnly want something like: d = while d != PAN: # code inserted here print Word, d, is correct # only prints when d == PAN HTH, -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] continuouse loop
Would a program using a continuouse loop such as in this code take up resources on the system if left for long period ? import sys while 1: self.data = sys.stdin.readline() self.function_1(data) What are my other options is I want to have a running program other programs communicate with it get responses from it ? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] continuouse loop
Monika Jisswel [EMAIL PROTECTED] wrote Would a program using a continuouse loop such as in this code take up resources on the system if left for long period ? Any running program takes up some resources but whether this one would increase its resource usage over time, which I assume is what you want to know, would depend on what it did with self.data and what happened in self.function_1. If function_1 did nothing that was resource intensive - like build a big list in memory or open a new file each time it was called (and not release it) - then it would be fine. But if function_1 stored data in a list or opened a new comms port on each call then yes it will eat up resources. import sys while 1: self.data = sys.stdin.readline() self.function_1(data) What are my other options is I want to have a running program other programs communicate with it get responses from it ? The trick to writing long running processes such as Windows services and Unix daemons is to ensure they are either stateless (the create use and free the needed resources in each operation) or utilise pools (pre-allocated sets of resources that are allocated to a function as needed and released by the function when done - if you run out of pool you take a decision to enlarge the pool or to stop servicing requests until resource becomes available - possibly using a queue if instant response is not critical) Thee are framweworks around, such as twisted, that help with these tasks. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Any way of monitoring a python program's memory utilization?
On Thu, 17 Jul 2008, Monika Jisswel wrote: I see no problem, if you open very BIG files then your memory will get filled up your system will halt, I'm going to disagree with you on this one. First, in general, it is not the case that opening a very large file will cause memory to be filled up. In general, only the portion of the file that is being processed needs to actually be in memory. A tarfile appears to be an exception to that general rule. The question is, why? Can that exception be avoided and a program that's processing a tar file be as well-behaved in terms of resource consumption as a program that processes other types of files? Second, although most resource constraint problems can often be addressed by buying more resource, that's not usually a good approach. Where, as here, the resource constraint surfaces only in rare cases (i.e., processing a tarfile), the better approach is to find out if something is out of whack with respect to that one case. Simply adding resources is a poor use of, um, resources, for a couple reasons. I'd rather spend my money on a nice dinner than on adding memory to a computer system that is perfectly adequate in every other way, other than in processing a single file. And adding resources, whether memory, disk, or CPU, is a band-aid: it gets you over this hump, but not the next. If I add enough memory to process a 4-Gb file, great, I can now process a 4-Gb file. But if I get a 6-Gb file in a couple months, I have to pull out the checkbook again. But managing the resource utilization is a scalable scheme. can you buy more food than your fridge can handle , and write to a list asking to invistigate the problem ? This is such an off-the wall analogy that it's difficult to respond to, but what the heck. First, I'm not writing to the list to ask it to investigate the problem. I'm writing to the list to find out what tools are available so that *I* can investigate the problem. Second, under this analogy, you're looking at a scenario where food is put into a refrigerator in containers, and when consumed, the containers are left in the refrigerator. Now, your solution here might be to keep buying more or larger refrigerators. Mine would be to see if I can get rid of all the empty containers that are uselessly occupying space in the refrigerator, so I can utilize the space for useful purposes (refrigerating food) rather than chilling empty containers for no reason. Back to the real Python case: now that I can monitor my memory usage, I can try various strategies to solve the problem, and I can do it with a subset of data. Instead of running the program on a 4Gb file and waiting to see if it blows up or halts my system in 15 minutes after processing a couple gig, I can run it with a much smaller 60 Mb file, and track its effects. For anyone who cares about the real issue: it seems that tarfile.py caches every member it processes in an internal list. The list isn't actually used if accessing the file as an iterator, so by reinitializing it to [], the memory consumption problem is avoided. This breaks other methods of the module, which are used to extract particular desired members, but in my case, that's okay. I'm currently experimenting to see if I can come up with a patch that will either allow both means of accessing the members (as an iterator and directly), or, as a less desirable alternative, if a parameter like cache=False is specified, allow access as an iterator and raise an exception if the other methods are used. Thanks to a couple tarfile.py experts on comp.lang.python for their insight on this. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Any way of monitoring a python program's memory utilization?
I m really sorry if no one of you liked/agreed with the fridge analogy but that's what my brain could come up with at the time, I have to say it's not a very scientific argument. but I only meant to say that if you are piping data into memory this data is larger than that memory then there is no problem with the code but with the data, I think this paragraph actually confirms some of it : For anyone who cares about the real issue: it seems that tarfile.py caches every member it processes in an internal list. The list isn't actually used if accessing the file as an iterator, so by reinitializing it to [], the memory consumption problem is avoided. This breaks other methods of the module, which are used to extract particular desired members, but in my case, that's okay. but I have to admit I was completely wrong and a new patch to the tarfile module will soon see the light to fix this problem for the rest of ur lives painlessly. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Question on how to do something.
Hello. I'm new to Python and I was wondering how to read all the files in a folder. I used this program or command for single files. import pprint pprint.pprint(open(r'c:\text\somefile.txt').readlines()) And if possible, is there a way to make it so that it waits at the end of each file for a confirmation to go onto the next file? Thanks ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] continuouse loop
Monika Jisswel wrote: Would a program using a continuouse loop such as in this code take up resources on the system if left for long period ? import sys while 1: self.data = sys.stdin.readline() self.function_1(data) Not much, I would think, until something is written to stdin of this program, and then it would depend on what function_1 does. What are my other options is I want to have a running program other programs communicate with it get responses from it ? If I understand what you're asking, there are a few options outlined in the python library reference, here: http://docs.python.org/lib/ipc.html I would add named pipes as another option for *nix, windows may have something similar. And, depending on what you're trying to accomplish maybe xmlrpclib, soappy, pyro, or perhaps even cgi. HTH, Marty ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] creating pop method for stack class
I am almost done with a stack class that I wrote: #!/usr/bin/python class Stack(list): def isempty(self): length = len(self) if length == 0: return True else: return False def peek(self): length = len(self) if length == 0: return 0 else: last_index = length - 1 return self[last_index] def stackpop(self): length = len(self) if length == 0: print Empty list! else: last_index = length - 1 stackpop_val = self[last_index] self = self[:last_index] return stackpop_val def push(self, value): return self.append(value) if __name__ == '__main__': x = True stack = Stack() print Pick an option to modify stack: while x == True: print 1) Peek at the last value print 2) Pop off the last value print 3) Push a value on the stack print 4) Print stack print 5) Quit Program choice_string = raw_input(Make a choice: ) try: choice = int(choice_string) except ValueError: sys.exit(Not an integer! Goodbye!) if choice == 1: if stack.isempty(): print Stack is empty else: peek_val = stack.peek() print peek_val elif choice == 2: pop_val = stack.stackpop() print pop_val elif choice == 3: push_val = raw_input(Push this value on stack: ) stack.push(push_val) elif choice == 4: print stack elif choice == 5: print Goodbye! x = False else: x = False sys.exit(Wrong response Goodbye!) My main problem seems to be getting this part to work: def stackpop(self): length = len(self) if length == 0: print Empty list! else: last_index = length - 1 stackpop_val = self[last_index] self = self[:last_index] return stackpop_val The easiest solution would be to use the pop method from list, but I decided I wanted to take a crack at writing my own pop method. Unfortunately, this always happens when I run the program: 1) Peek at the last value 2) Pop off the last value 3) Push a value on the stack 4) Print stack 5) Quit Program Make a choice: 3 Push this value on stack: 1 1) Peek at the last value 2) Pop off the last value 3) Push a value on the stack 4) Print stack 5) Quit Program Make a choice: 3 Push this value on stack: blah 1) Peek at the last value 2) Pop off the last value 3) Push a value on the stack 4) Print stack 5) Quit Program Make a choice: 3 Push this value on stack: blah blah 1) Peek at the last value 2) Pop off the last value 3) Push a value on the stack 4) Print stack 5) Quit Program Make a choice: 2 blah blah 1) Peek at the last value 2) Pop off the last value 3) Push a value on the stack 4) Print stack 5) Quit Program Make a choice: 4 ['1', 'blah', 'blah blah'] How come the stack doesn't shrink when I pop off the last value? I tested the code in the interpreter: lista = [1,2,3,4] lista[:len(lista)-1] [1, 2, 3] lista = lista[:len(lista)-1] lista [1, 2, 3] Any hints? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] parsing sendmail logs
2008/7/15 Martin Walsh [EMAIL PROTECTED]: Any pragmatic advice on building or working with a framework to get to the point where i can do analysis on my logs would be cool. As an exercise, I think it would be a reasonable approach to write python derivatives of the shell commands being used, perhaps tailored to the data set, to get a feel for working with text data in python. Then ask questions here if you get stuck, or need optimization advice. I think you'll find you can accomplish this with just a few lines of python code for each (sort -u, grep, awk '{print $n}', etc), given your use of the commands in the examples provided. Write each as a function, and you'll end up with code you can reuse for other log analysis projects. Bonus! HTH, Marty Hi Marty, Thanks for the input. I like the idea of writing tailored versions of the standard unix tools. I think what has held me back from writing more than a few scripts based on someone elses code is a lack of clarity about what i'm wanting to write. I've done a bit of web programming in ASP,PHP and Perl mostly in the presentation layer, but the shift in domain to sysadmin tasks has for some reason has been difficult. To essentially re-write sort -u in python has the advantage for me that i use sort _alot_ so i'm familiar with the concept and it's a small enough tasks to feel doable. :-) Your suggestion also provides an insight into how to program that i find easy to forget. which is to break things down into smaller pieces. Cheers, nibuh. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] parsing sendmail logs
2008/7/16 Jeff Younker [EMAIL PROTECTED]: Parsers as referenced in your link are intended for heavy-duty lifting such as parsing programming languages. Sendmail logs are very simple, so those parsers are vast overkill. Split on whitespace combined with regular expressions should be up to the job. -jeff Jeff, Thanks for the clarification, I was looking at these parsers thinking they were overkill. split and regex for version 0.0.0.1 of my script looks like the order of the day :-) Cheers, ram, ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Guidance on jump-starting to learn Python
I have the challenge / opportunity to learn Python quickly. I am technically-minded, but I am not a programmer. When I have tried / used Python before (I've written 5-6 python programs/utilities), it has been solving a particular issue but not learning the proper structure/procedures to learn Python (nor any other programming language). I humbly admit I have cut corners, so I have bad habits. I have been advised to start with the basics but at an accelerated pace. Any recommended homework assignments? I have two books as well: Core Python Programming from Wesley Chun , Second Edition. Python Programming for the Absolute Beginner, Second Edition. Thanks so much for your advice/help in advance. Steve ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] creating pop method for stack class
First, a tip: Instead of lista[:len(lista)-1], you can (and should) just write lista[:-1]. Now, what if we wrap that in a function: def shorten(lst): ... lst = lst[:-1] # identical to: lst = lst[:len(lst)-1] ... Then test it: lista = [1, 2, 3, 4] shorten(lista) What do you think will be the result of: print lista ? I see what you mean. I have tested it, and I have gotten a weird result: def shorten(lst): ... lst = lst[:-1] ... lista = [1,2,3,4] shorten(lista) print lista [1, 2, 3, 4] lista = [1,2,3,4] lista = lista[:-1] print lista [1, 2, 3] Strange...why does it work outside of the function but not in it? Let me try something else: def shorten(lst): ... lst = lst[:-1] ... return lst ... lista = [1,2,3,4] shorten(lista) [1, 2, 3] print lista [1, 2, 3, 4] lista = shorten(lista) print lista [1, 2, 3] Huh, how do you explain that? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor