[Tutor] Fwd: Problem reading large files in binary mode
Hello I am new to python programming. while trying it out i find that in my code file io.read is not reading large files particularly over 1 gb. my code is posted below. i am working on python 3.3 on windows with ntfs partition and intel corei3 ram 3gb. the execution always stops saying error with py.exe but idle editor and idle window remains open. thank you George ##function module generates md5 for given file data import hashlib import io import os def filemd5(file="g:\\filelargerthan1gb.iso"): #print ("reached here") #print ("File for processing %s",file) try: filelen=os.path.getsize(file) except PermissionError: print("Don't have permission for ",file,".\tTry running as administrator") return '' if filelen>1073741824: print ("file len greater than 1gb.\nNot hashing") return '' try: f=open(file,'rb', buffering=0) #i have tried without buffering also except PermissionError: print("Don't have permission for ",file,".\tTry running as administrator") return '' try: #print ("Readding") fcontents=f.read() #print ("Read successfully") hashvalue=hashlib.md5(fcontents).hexdigest() #print ("md5 successfully") except: hashvalue='' print ("Error during reading md5") f.close() #print (hashvalue) return hashvalue filemd5() --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] How can I let the Python Console display more decimal precision?
Hi All: I am a newbie at the Python. I type "26/12" in Python Console and get result of "2". It is obvious that the corresponding result should be 2... I don't know why the Console only returns the integer part of true result. Anyone can help me out? Thanks David ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] MIT - Free Python course started today
Sort of off topic, (don't kill me) but then again very useful for beginners! MIT started free Python course today: https://www.edx.org/course/mitx/mitx-6-00-1x-introduction-computer-1841 Unfortunately they are using Python 2.7 :-( You can even get a certificate if you finish with high enough score (will cost you something for certificate) Anyway, even if partially off topic I think it may be beneficiary for some beginners here. I'm already going through the lessons :-) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] A couple newbie questions about Python
Thanks very much Alan. As for the my concern about inaccuracy in float math, I suppose I am concerned because I was not aware of the issue before, and I wonder how you deal with such things when you need accuracy for financial things. Deb in WA, USA > -Original Message- > From: alan.ga...@btinternet.com > Sent: Wed, 11 Jun 2014 23:48:37 +0100 > To: tutor@python.org > Subject: Re: [Tutor] A couple newbie questions about Python > > On 11/06/14 21:46, Deb Wyatt wrote: >> Hi. Everywhere I have read, the 'standard practice' for indentation is >> 4 spaces, > > That's a style recommendation. Python doesn't care. > But your readers will. 2 spaces is the absolute minimum, > 8 spaces is about the absolute maximum. Outside that it > gets hard to read the code. > > 3, 4 or 5 spaces is pretty good and you are unlikely > to get complaints except from style pedants or if you > are submitting code for the standard library where they > like to stick with the official guidance. > > >> I just recently became aware of the inaccuracy of calculations using >> floats > > and I am concerned about that. > > The inaccuracies are an inevitable result of the way your computer > processes floating point numbers. > > In what way are you concerned? Its not a Python issue - the exact same > issues occur in any computer - or even your pocket calculator. > If it concerns you in Excel or in Visual Basic/Java/C++ etc too then the > good news is that Python has alternative renderings that can often > reduce/eliminate them - but at the cost of speed and complexity. > > > HTH > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.flickr.com/photos/alangauldphotos > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor Protect your computer files with professional cloud backup. Get PCRx Backup and upload unlimited files automatically. Learn more at http://backup.pcrx.com/mail ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] AttributeError: 'module' object has no attribute 'start'
Hi All, I am new to wxPython.I have made a simple GUI that contains a button and by pressing that button i am calling another .py file(top_block.py)...But i am getting error using the command: top_block.start() The error is: AttributeError: 'module' object has no attribute 'start' The code is as attached.I am using python 2.7.3.Any improvements in the code are also welcome.The same error is received when i use'top_block.run()'.Is there any alternative to this commands? Regards, Ali import wx class MyApp(wx.App): def OnInit(self): self.frame = MyFrame(None, title="The Main Frame") self.SetTopWindow(self.frame) self.frame.Show() return True class MyFrame(wx.Frame): def __init__(self, parent, id=wx.ID_ANY, title="", pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE, name="MyFrame"): super(MyFrame, self).__init__(parent, id, title, pos, size, style, name) # Attributes self.panel = wx.Panel(self) self.panel.SetBackgroundColour(wx.BLACK) self.button3=wx.Button(self, -1, ' Execute ', wx.Point(235, 90), wx.DefaultSize) self.Bind(wx.EVT_BUTTON, self.Execute,self.button3) def Execute(self,event): import top_block top_block.start() if __name__ == "__main__": app = MyApp(False) app.MainLoop() import os import wx class MyApp(wx.App): def OnInit(self): self.frame = MyFrame(None, title="Bitmaps") self.SetTopWindow(self.frame) self.frame.Show() return True class MyFrame(wx.Frame): def __init__(self, parent, id=wx.ID_ANY, title="", pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE, name="MyFrame"): super(MyFrame, self).__init__(parent, id, title, pos, size, style, name) # Attributes self.panel = wx.Panel(self) img_path = os.path.abspath("a.png") bitmap = wx.Bitmap(img_path, type=wx.BITMAP_TYPE_ANY) self.bitmap = wx.StaticBitmap(self.panel,bitmap=bitmap) if __name__ == "__main__": app = MyApp(False) app.MainLoop() ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] A couple newbie questions about Python
I wonder how you deal with such things when you need accuracy for financial things. Financial applications traditionally work in the lowest unit of currency and use integers. For display purposes they convert the pennies into dollars/cents or pounds/pence or whatever. Alan Gauld Author of the Learn To Program website http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How can I let the Python Console display more decimal precision?
Hi, from the question you're using python 2.x you can do either: 26.0/12 (float divide by int - it retypes both to floats and gets you 2.) or at the beginning do: from __future__ import division That will activate python3 way of dividing - which gives you 2. Lukas. On 06/12/2014 02:48 AM, Marino David wrote: Hi All: I am a newbie at the Python. I type "26/12" in Python Console and get result of "2". It is obvious that the corresponding result should be 2... I don't know why the Console only returns the integer part of true result. Anyone can help me out? Thanks David ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fwd: Problem reading large files in binary mode
Mirage Web Studio wrote: > I am new to python programming. while trying it out i find that in my > code file io.read is not reading large files particularly over 1 gb. my > code is posted below. i am working on python 3.3 on windows with ntfs > partition and intel corei3 ram 3gb. the execution always stops saying > error with py.exe but idle editor and idle window remains open. > try: > #print ("Readding") > fcontents=f.read() In the line above you are reading the whole file into memory. > #print ("Read successfully") > hashvalue=hashlib.md5(fcontents).hexdigest() > #print ("md5 successfully") Try reading the file in chunks instead: CHUNKSIZE = 2**20 hash = hashlib.md5() while True: chunk = f.read(CHUNKSIZE) if not chunk: break hash.update(chunk) hashvalue = hash.hexdigest() ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] A couple newbie questions about Python
Please don't top post, it makes following a long thread extremely difficult, thanks. On 12/06/2014 03:47, Deb Wyatt wrote: Thanks very much Alan. As for the my concern about inaccuracy in float math, I suppose I am concerned because I was not aware of the issue before, and I wonder how you deal with such things when you need accuracy for financial things. Deb in WA, USA Besides Alan's previous statement about using integers you can also use things like Python's decimal module see https://docs.python.org/3/library/decimal.html#module-decimal -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] MIT - Free Python course started today
Thanks a lot. On 06/12/2014 01:42 AM, Mario Py wrote: Sort of off topic, (don't kill me) but then again very useful for beginners! MIT started free Python course today: https://www.edx.org/course/mitx/mitx-6-00-1x-introduction-computer-1841 Unfortunately they are using Python 2.7 :-( You can even get a certificate if you finish with high enough score (will cost you something for certificate) Anyway, even if partially off topic I think it may be beneficiary for some beginners here. I'm already going through the lessons :-) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor -- С уважением, Самодед Владимир SVAJ-RIPE|SVA88-UANIC ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] MIT - Free Python course started today
On Thu, Jun 12, 2014 at 1:42 AM, Mario Py wrote: > Sort of off topic, (don't kill me) but then again very useful for beginners! > > MIT started free Python course today: > > https://www.edx.org/course/mitx/mitx-6-00-1x-introduction-computer-1841 > > Unfortunately they are using Python 2.7 :-( > You can even get a certificate if you finish with high enough score (will > cost you something for certificate) > > Anyway, even if partially off topic I think it may be beneficiary for some > beginners here. I'm already going through the lessons :-) Thank you, I'm signing up! The same organization is doing an introduction to Linux course that starts on August 1st. I'm signed up for that one as well: https://www.edx.org/course/linuxfoundationx/linuxfoundationx-lfs101x-introduction-1621 -- Dotan Cohen http://gibberish.co.il http://what-is-what.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] A couple newbie questions about Python
On Thu, Jun 12, 2014 at 1:27 AM, Alex Kleider wrote: > On 2014-06-11 20:08, Dave Angel wrote: > >> I learned programming in 1967 with Fortran, and McCracken spent a >> chapter warning about that same thing. Probably everything he >> warned about still applies to Python and modern computers. > > A google search for "McCracken" did not yield anyone that seems to fit the > person you reference. Can you clarify, please? 1961 A Guide to Fortran Programming openlibrary.org/works/OL4628575W 1964 Numerical Methods and Fortran Programming openlibrary.org/books/OL5914708M 1965 A Guide to Fortran IV Programming openlibrary.org/books/OL5953402M 1967 Fortran with Engineering Applications openlibrary.org/books/OL5539818M snippets: books.google.com/books?id=qQY_IAAJ&dq=editions:STANFORD36105002062847 1974 A Simplified Guide to Fortran Programming openlibrary.org/works/OL4628579W 1972 Numerical Methods with Fortran IV Case Studies openlibrary.org/books/OL4559608M 1984 Computing for Engineers and Scientists with Fortran 77 openlibrary.org/books/OL3180840M ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] AttributeError: 'module' object has no attribute 'start'
Hi, On 12 June 2014 05:51, jason sam wrote: > > Hi All, > I am new to wxPython.I have made a simple GUI that contains a button and by > pressing that button i am calling another .py file(top_block.py)...But i am > getting error using the command: > > top_block.start() > > The error is: > > AttributeError: 'module' object has no attribute 'start' The message states that there's no attribute in the module called 'start', which is correct -- top_block.py doesn't contain anything named 'start'. (What made you think that modules have a magic method start() that causes them to run?) You should probably learn more about Python itself, name binding, module objects etc. > > The code is as attached.I am using python 2.7.3.Any improvements in the code > are also welcome.The same error is received when i use'top_block.run()'.Is > there any alternative to this commands? I'm not a wxPython expert but you should probably be creating an instance of the the frame class defined in top_block and then call show() that, from your wxgui.py, when your button click handler is called. I would also rename the classes to represent what they are. (MyFrame is not exactly useful and is doubly ambiguous as you have 2 defined in different modules.) Suggestion: Try to fix your program with both the main program and the top bar in one module. And then only when this works try moving it back out to another module again, if required. HTH Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] AttributeError: 'module' object has no attribute 'start'
On Thu, Jun 12, 2014 at 11:41:58AM +0100, Walter Prins wrote: > (What made you think that modules have a magic method > start() that causes them to run?) You should probably learn more > about Python itself, name binding, module objects etc. That's what this list is for! -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How can I let the Python Console display more decimal precision?
On Thu, Jun 12, 2014 at 08:48:25AM +0800, Marino David wrote: > Hi All: > > I am a newbie at the Python. > > I type "26/12" in Python Console and get result of "2". > > It is obvious that the corresponding result should be 2... I don't > know why the Console only returns the integer part of true result. Anyone > can help me out? Try this instead: 26.0/12 and it will print a fractional number instead of an int: py> 26.0/12 2.1665 What's going on? Back in the early mists of time, when Python first came out, Python's creator Guido van Rossum decided that the / division operator should behave like in the C programming language. In C, division of two integers performs *integer division*, and drops the remainder, while division of one or more floating point number keeps the remainder as a fraction: 1/2 => 0 1/2.0 => 0.5 That was one of those decisions that seemed like a good idea at the time, but turned out to be a mistake. But for backwards compatibility, Python had to keep it until recently. In Python version 3, / now does calculator division, like you expect. But in Python 2, you have to either convert one or both numbers to a float, or you can put this at the top of your program: from __future__ import division Note that there are TWO underscores at the beginning and end of "future". If you want integer division, where the remainder is ignored, you can use the // operator: py> 26.0//12 2.0 -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] A couple newbie questions about Python
On 12/06/14 09:18, Mark Lawrence wrote: Besides Alan's previous statement about using integers you can also use things like Python's decimal module see https://docs.python.org/3/library/decimal.html#module-decimal Although Decimal doesn't solve the issue of rounding errors for financial calculations (neither do pennies) nor the issues of repeating results like 1/7 It just moves them into the more familiar territory of decimal numbers rather than binary. So at least what you write is represented accurately. As Steven said in his reply, floating point on computers is hard. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] AttributeError: 'module' object has no attribute 'start'
On 12/06/14 05:51, jason sam wrote: Hi All, I am new to wxPython.I have made a simple GUI that contains a button and by pressing that button i am calling another .py file(top_block.py)... No you are not. You are importing it and then trying to access something called start which doesn't exist. importing is not the same as running a script. For a start the _name__ attribute will not be __main__ so your if clause at the bottom won't be executed. But the class definition code will have been run so you can access and create those classes from your wxGUI module. However, it is very strange practice to try to create a second GUI program from a first (not totally unheard of but uncommon). More usually you would define a dialog and open that from your Execute method. top_block.start() The error is: AttributeError: 'module' object has no attribute 'start' Please always post the full error message not just a summary. It has all sorts of useful extra details in there. In this case it doesn't matter because as the error says your module has no start attribute - because you didn't create one. code are also welcome.The same error is received when i use'top_block.run()'.Is there any alternative to this commands? Yep, you didn't define a run() function either. modules can only execute what you define within them (and one or two special case attributes defined by Python; all starting with __ Thee are several other oddities in your code but this is probably enough for now. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] AttributeError: 'module' object has no attribute 'start'
On 12/06/2014 05:51, jason sam wrote: Hi All, I am new to wxPython.I have made a simple GUI that contains a button and by pressing that button i am calling another .py file(top_block.py)...But i am getting error using the command: top_block.start() The error is: AttributeError: 'module' object has no attribute 'start' The code is as attached.I am using python 2.7.3.Any improvements in the code are also welcome.The same error is received when i use'top_block.run()'.Is there any alternative to this commands? Regards, Ali I suspect that you'll get better answers on the wxpython list, especially consdiering that you asked there all of two minutes before asking here. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] AttributeError: 'module' object has no attribute 'start'
On Thu, Jun 12, 2014 at 05:47:23PM +0100, Mark Lawrence wrote: > I suspect that you'll get better answers on the wxpython list, > especially consdiering that you asked there all of two minutes before > asking here. This is not aimed specifically at Mark. Can we please stop chastising people for asking questions in different forums? There's nothing wrong with asking in a few different places simultaneously and getting answers from people with different perspectives. Nor should people have to ask those questions sequentially ("ask on tutor list, wait a week, then ask on the wxpython list, then wait another week, then ask somewhere else") when they can do so in parallel. In other words, if you ask a question in one place, you don't necessarily have to wait before asking it again elsewhere. If you (generic you, not just Mark) happen to be members of multiple mailing lists or other forums, and you see the same question in both places, feel free to link to good answers in the other forum. Otherwise, just remember that what is a duplicate question to you, is not duplicate to those who aren't members of both forums. Thank you. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] AttributeError: 'module' object has no attribute 'start'
On 12 June 2014 13:11, Steven D'Aprano wrote: > On Thu, Jun 12, 2014 at 11:41:58AM +0100, Walter Prins wrote: > >> (What made you think that modules have a magic method >> start() that causes them to run?) You should probably learn more >> about Python itself, name binding, module objects etc. > > That's what this list is for! Of course. The way the OP asked his question, stating he's a beginner to wxPython, but omitting to state that he's also Python beginner, leaves one with the impression that he might be (or think that he is) relatively/more skilled at at Python. The nature of the problem he's having however indicates a basic lack of understanding of Python itself, which should be easily remedied by a bit of self study, which, given that he's teaching himself wxPython is probably realistic, and which is why I suggested it. Of course, if he does run into further questions then he's most welcome to ask, apologies if I might've given a different impression. Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] code review
On 12Jun2014 00:38, Alan Gauld wrote: On 11/06/14 11:43, Adam Gold wrote: # create snapshot names like the following: 2014-06-10T01-00-01.vm1.img.bz2 for i in vgxenList: DATE = datetime.datetime.now().strftime("%Y-%m-%d" + "T" + "%H-%M-%S") Why use addition? You could just insett the literal T... DATE = datetime.datetime.now().strftime("%Y-%m-%dT%H-%M-%S") Also using all caps for the name suggests a constant by convention. vgxenName = "/dev/vgxen/" lvName = i Just further to these two snippets, "/dev/vgxen/" is just the kind of thing you would treat as a "constant" (Python doesn't really have constants, just the convention that names in all UPPERCASE represent stable ad hoc values which won't change, and would be "constants" in some other languages.) So at the top of your script (after imports) you might have: VXGEN_DIR = "/dev/vgxen" and use it later. Note, no trailing slash in that dir name. In view of this, later where you append to backupList you might go: snap_path = os.path.join(VXGEN_DIR, snapName) backupList.append(snap_name) os.path.join is the usual way to assemble pathnames form path components; it is in principle platform independent. BTW, someone has proably mentioned it, but in case not: names like this_that are the convention for normal variables in Python as opposed to thisThat camelcase names. The main use of camelcase in Python names is class names "This That". It doesn't affect your code in any functional way, but others will find you code slightly more readable. These common conventions are outlined in PEP 8: http://legacy.python.org/dev/peps/pep-0008/ Worth a read. It is only strict for stdlib module source code, but adherence is common in most code. Cheers, Cameron Simpson A good catchword can obscure analysis for fifty years. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] code review
On 13Jun2014 12:28, Cameron Simpson wrote: snap_path = os.path.join(VXGEN_DIR, snapName) backupList.append(snap_name) Sorry, "snap_path" in both lines:-( Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor