Re: working
in 753638 20160212 185728 sohcahto...@gmail.com wrote: >On Friday, February 12, 2016 at 1:47:24 AM UTC-8, Mohammed Zakria wrote: >> hello >> i want to know the company that ican work as freelance python devloper > >There are some recruiters that read this mailing list and will send >unsolicited e-mail about job ope >nings, but they might pass right over you if you're not willing to spend the >time to proofread your >messages. The standard of his English might not be a problem but in a previous post he indicated that he is an absolute beginner. -- https://mail.python.org/mailman/listinfo/python-list
confusing installation on windows? was: Re:
On 13-2-2016 2:43, Joel Goldstick wrote: > On Fri, Feb 12, 2016 at 3:16 PM, Manas Soni wrote: > >> >> I have downloaded python and when I click on it, it asks me to repair >> which I do, it then says successful however when I click on it again it >> won’t let me on it >> Sent from Mail for Windows 10 >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > I don't do windows, so I can't give you an answer. To the group, this has > come up so consistantly lately. Maybe a windows python user could explain > why this is so confusing to newbies on windows? > I think it could be because of the confusing start menu in recent windows versions. Perhaps they keep clicking the tile that shows the installer (as a 'recent document' or 'download'), rather than the new tile that would show the actual Python/idle/documentation icon. I can't check right now because here I have windows 7 (with a sane start menu) but will have a look at how it's presented when freshly installing a new python on my machine at office next week (which has windows 8...) Irmen -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Not Working as expected on Win 8 and above.
On Saturday 13 February 2016 07:13 AM, Joel Goldstick wrote: On Fri, Feb 12, 2016 at 3:16 PM, Manas Soni wrote: I have downloaded python and when I click on it, it asks me to repair which I do, it then says successful however when I click on it again it won’t let me on it Sent from Mail for Windows 10 -- https://mail.python.org/mailman/listinfo/python-list I don't do windows, so I can't give you an answer. To the group, this has come up so consistantly lately. Maybe a windows python user could explain why this is so confusing to newbies on windows? Hello, Just to add to the above discussion, i find that when my workplace updated from win 7 to win 8.1 with fresh install, i downloaded the official python 3.5 and installed it. Everything went well during installation, but, i couldn't find the default install python directory (maybe i didn't pay attention earlier), later, after some scratching my head and other intelligent thoughts and experiments i found it got installed in the users hidden appdata folder by default(confusing as i expected it to either get installed in a root folder or program files and also wondering why). I used pycharm for working on previous win version, so after installing the same again i selected the python.exe file as default interpreter. The big headache i found is that previously i could easily install packages from the pycharm interface, but currently the that thing is not working nor could i use it to run any of my previous apps(scipts) i created on win 7 (maybe not a python problem and i may find a workaround). Finally as i had to get my work done, i used a (trusted) portable version of python3.4 with preinstalled modules and that got me working. Wonder why is that so hard to work on win with python. I work on linux at home and i never faced such a problem on it because it is natively supported on it. Wonder when will microsoft understand that some programs need to be natively supported even if they are not made by them. I love windows for what they are but i hold linux even more dearer for what it is. George PS : The system has upgraded to Win 10 but not tested the python installation on it. -- https://mail.python.org/mailman/listinfo/python-list
made a simple rhythm sample mixer for fun (think Roland TR-909)
Hi, For fun and to learn a bit from messing around a little with audio samples, I've created a rhythm sample mixer inspired by the Roland TR-909 drum machine. Basically you write rhythm sample patterns and it then sequences and mixes them into a output wav file or streams it to your speakers. Songs are built up from pattern sequences, where a pattern is built up from trigger bars for the used instruments. The tool also has a simple command line interface to edit patterns and play samples etc. As an example here is a fragment of one of the example songs; [song] patterns = pat1 pat2 pat3 pat2b pat3b outro [pattern.pat2] hihat2 = x...x... x...x... kick7 = x... kick9 = x... snare2 = x... You can find it here (also some examples): https://github.com/irmen/rhythmbox Python 3.x is required, also needs pyaudio if you want streaming. Other than that, I've found that the standard age-old audioop module may be limited, but is enough to build some basic sample mixing stuff with. I'm interested in what rhythm loops you can come up with! have fun, Irmen -- https://mail.python.org/mailman/listinfo/python-list
Re: (unknown)
On 12 February 2016 at 21:39, Mark Lawrence wrote: > On 12/02/2016 20:16, Manas Soni wrote: >> >> >> I have downloaded python and when I click on it, it asks me to repair >> which I do, it then says successful however when I click on it again it >> won’t let me on it >> Sent from Mail for Windows 10 >> > > Please search the archives as this has been asked and answered repeatedly > over the last few months. I've seen the "repair" question asked many times but I don't actually recall seeing a solution to this particular problem. What causes it and how do you solve it? Or can someone point to a thread about this that actually contains the solution rather than the many that look like this one did before I added this post? Does the error happen when running the installer or when trying to launch IDLE or something after install? There are a lot of questions like this about installing Python 3.5 on Windows and AFAICT they come under the following categories (have I missed anything?): 1) XP users - I think the 3.5.1 installer gives a proper error message for this now. 2) ms-api-x.dll - update C runtime from MS - the installer should probably give a proper error message for this too 3) error code 0x8023482348 (or some hex string) - some Windows problem with temporary files. 4) New user can't work out how to "run python" after installing. Should be able to find it in the programs menu I guess but perhaps it's not easy to find on newer Windows >= 8. 5) modify/repair/install - like this one. I don't know what the solution is. Perhaps there should be a wiki page listing the common problems and solutions so that people can be pointed to that instead of being told to search the archives. I'm not sure how you'd go about creating one of those and realistically it should be novice-friendly so it really needs screenshots of how it looks under different Windows versions and takes people right through to the point of say running a command in IDLE. Not being a Windows user it's not easy for me to provide the necessary level of detail for that. Also as concerns problem 2) presumably the installer could detect this and point users to the solution as it does for XP. -- Oscar -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Not Working as expected on Win 8 and above.
On Sat, Feb 13, 2016 at 7:35 AM, MWS wrote: > couldn't find the default install python directory (maybe i didn't pay > attention earlier), later, after some scratching my head and other > intelligent thoughts and experiments i found it got installed in the users > hidden appdata folder by default(confusing as i expected it to either get > installed in a root folder or program files and also wondering why). The new installer uses the standard locations for per-user and per-machine installations, but you can change it to use whatever you want. The following are the default installation locations (using "shell:" links). per-user install shell:UserProgramFiles\Python\PythonXY[-32] per-machine install shell:ProgramFiles[x86]\PythonXY[-32] UserProgramFiles defaults to "shell:Local AppData\Programs". You can relocate it, but I'd only do that for a new account. -- https://mail.python.org/mailman/listinfo/python-list
problem with dateutil
I am writing a program that has to deal with various date/time formats and convert these into timestamps. It looks as if dateutil.parser.parse should be able to handle about any format, but what I get is: datetimestr = '2012-10-22 11:22:33' print(dateutil.parser.parse(datetimestr)) result: datetime.datetime(2012, 10, 22, 11, 22, 33) However: datetimestr = '2012:10:22 11:22:33' print(dateutil.parser.parse(datetimestr)) result: datetime.datetime(2016, 2, 13, 11, 22, 33) In other words, it's getting the date wrong when colons are used to separate :MM:DD. Is there a way to include this as a valid format? -- https://mail.python.org/mailman/listinfo/python-list
Re: problem with dateutil
On 02/13/2016 09:58 AM, Tom P wrote: I am writing a program that has to deal with various date/time formats and convert these into timestamps. It looks as if dateutil.parser.parse should be able to handle about any format, but what I get is: datetimestr = '2012-10-22 11:22:33' print(dateutil.parser.parse(datetimestr)) result: datetime.datetime(2012, 10, 22, 11, 22, 33) However: datetimestr = '2012:10:22 11:22:33' print(dateutil.parser.parse(datetimestr)) result: datetime.datetime(2016, 2, 13, 11, 22, 33) In other words, it's getting the date wrong when colons are used to separate :MM:DD. Is there a way to include this as a valid format? Yes, there is a way to specify your own format. Search the datetime documentation for datetime.strptime(date_string, format) Gary Herron -- Dr. Gary Herron Department of Computer Science DigiPen Institute of Technology (425) 895-4418 -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Not Working as expected on Win 8 and above.
On 2/13/2016 5:35 AM, MWS wrote: Just to add to the above discussion, i find that when my workplace updated from win 7 to win 8.1 with fresh install, i downloaded the official python 3.5 and installed it. Everything went well during installation, but, i couldn't find the default install python directory (maybe i didn't pay attention earlier), later, after some scratching my head and other intelligent thoughts and experiments i found it got installed in the users hidden appdata folder by default(confusing as i expected it to either get installed in a root folder or program files and also wondering why). Based on my experience with installing Python 3.5.0, I ran into the same problem by clicking on the "Download Python 3.5.0" link on the Python download page and used the python-3.5.0.exe installer. Since nothing worked as I expected, I uninstalled that installer version of Python. Digging through the specific release section, I downloaded the Windows x86-64 executable installer (python-3.5.0-amd64.exe). That installer behaved exactly as I expected. In fact, this is the installer I've always used for previous versions. Besides the focus of the content files, the python-3.5.0.exe and python-3.5.0-amd64.exe installers don't behave exactly the same. Thanks, Chris R. -- https://mail.python.org/mailman/listinfo/python-list
What is heating the memory here? hashlib?
Hello all. I'm running in a very strange (for me at least) problem. def getHash(self): bfsz=File.blksz h=hashlib.sha256() hu=h.update with open(self.getPath(),'rb') as f: f.seek(File.hdrsz) # Skip header b=f.read(bfsz) while len(b)>0: hu(b) b=f.read(bfsz) fhash=h.digest() return fhash hdrsz is always 4K here. All files are greater than 4K. If I use a 40MB bfsz this tooks all my memory very quickly. After few hundreds of files it begins to swap ending up with the program being killed (BTW, I'm using linux kubuntu 14.04). If I reduce bfsz to 1MB it successfully completes my full test (~10 files) reaching about 6GB of memory. If I reduce further bfsz to 16KB there is no noticeable memory taken!! I have tried the following code, but it didn't fix the problem: def getHash(self): bfsz=File.blksz h=hashlib.sha256() hu=h.update with open(self.getPath(),'rb') as f: husz=8192 f.seek(File.hdrsz) # Skip header b=f.read(bfsz) while len(b)>0: for i in range(0,len(b),husz): hu(b[i:i+husz]) b=f.read(bfsz) fhash=h.digest() return fhash What is wrong here?! Thanks for any help/comments. Paulo -- https://mail.python.org/mailman/listinfo/python-list
Re: Storing a big amount of path names
In my application I have used two approaches: 1. To store paths as a tree (as directories for a tree. 2. For long list of similar paths, to store difference of strings. Though this was c++/obj-c project, I can share a diff code with you if you drip me a line (mkondrashin & gmail , com) -- https://mail.python.org/mailman/listinfo/python-list
Re: problem with dateutil
On 02/13/2016 07:13 PM, Gary Herron wrote: On 02/13/2016 09:58 AM, Tom P wrote: I am writing a program that has to deal with various date/time formats and convert these into timestamps. It looks as if dateutil.parser.parse should be able to handle about any format, but what I get is: datetimestr = '2012-10-22 11:22:33' print(dateutil.parser.parse(datetimestr)) result: datetime.datetime(2012, 10, 22, 11, 22, 33) However: datetimestr = '2012:10:22 11:22:33' print(dateutil.parser.parse(datetimestr)) result: datetime.datetime(2016, 2, 13, 11, 22, 33) In other words, it's getting the date wrong when colons are used to separate :MM:DD. Is there a way to include this as a valid format? Yes, there is a way to specify your own format. Search the datetime documentation for datetime.strptime(date_string, format) Gary Herron Thanks. I started out with datetime.strptime but AFAICS that means I have to go through try/except for every conceivable format. Are you saying that I can't use dateutil.parser? -- https://mail.python.org/mailman/listinfo/python-list
Re: problem with dateutil
On 02/13/2016 12:27 PM, Tom P wrote: On 02/13/2016 07:13 PM, Gary Herron wrote: On 02/13/2016 09:58 AM, Tom P wrote: I am writing a program that has to deal with various date/time formats and convert these into timestamps. It looks as if dateutil.parser.parse should be able to handle about any format, but what I get is: datetimestr = '2012-10-22 11:22:33' print(dateutil.parser.parse(datetimestr)) result: datetime.datetime(2012, 10, 22, 11, 22, 33) However: datetimestr = '2012:10:22 11:22:33' print(dateutil.parser.parse(datetimestr)) result: datetime.datetime(2016, 2, 13, 11, 22, 33) In other words, it's getting the date wrong when colons are used to separate :MM:DD. Is there a way to include this as a valid format? Yes, there is a way to specify your own format. Search the datetime documentation for datetime.strptime(date_string, format) Gary Herron Thanks. I started out with datetime.strptime but AFAICS that means I have to go through try/except for every conceivable format. Are you saying that I can't use dateutil.parser? Well now... If by "every conceivable format" you are including formats that the author of dateutil.parser did not conceive of, then of course you cannot use dateutil.parser. But you have the code for dateutil.parser -- perhaps you could modify it to accept whatever odd formats you care about. Gary Herron -- Dr. Gary Herron Department of Computer Science DigiPen Institute of Technology (425) 895-4418 -- https://mail.python.org/mailman/listinfo/python-list
Re: problem with dateutil
On 13/02/2016 17:58, Tom P wrote: I am writing a program that has to deal with various date/time formats and convert these into timestamps. It looks as if dateutil.parser.parse should be able to handle about any format, but what I get is: datetimestr = '2012-10-22 11:22:33' print(dateutil.parser.parse(datetimestr)) result: datetime.datetime(2012, 10, 22, 11, 22, 33) However: datetimestr = '2012:10:22 11:22:33' print(dateutil.parser.parse(datetimestr)) result: datetime.datetime(2016, 2, 13, 11, 22, 33) In other words, it's getting the date wrong when colons are used to separate :MM:DD. Is there a way to include this as a valid format? From http://labix.org/python-dateutil#head-a23e8ae0a661d77b89dfb3476f85b26f0b30349c parserinfo This parameter allows one to change how the string is parsed, by using a different parserinfo class instance. Using it you may, for example, intenationalize the parser strings, or make it ignore additional words. HTH. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: What is heating the memory here? hashlib?
I meant eating! :-) -- https://mail.python.org/mailman/listinfo/python-list
Re: What is heating the memory here? hashlib?
On Sun, Feb 14, 2016 at 9:26 AM, Paulo da Silva wrote: > I meant eating! :-) Heh, "heating" works too - the more you use memory, the more it heats up :) I'm assuming this is inside "class File:" and you have class members for your constants like header size? There's no context for the name "File" otherwise. What happens if, after hashing each file (and returning from this function), you call gc.collect()? If that reduces your RAM usage, you have reference cycles somewhere. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Changing A Subscription Option
Hello. Is there a way to change my subscription option from digest to individual e-mails? I couldn't find any information on the list web page: https://mail.python.org/mailman/listinfo/python-list. I've tried filling out the subscription form again, but the result was an automated e-mail about someone trying to alter my subscription. I've also sent an e-mail to python-list-requ...@python.org, but I haven't received a response. -- Thanks, Heaven Hodges -- https://mail.python.org/mailman/listinfo/python-list
Re: Changing A Subscription Option
On 13/02/2016 23:15, Heaven Hodges wrote: Hello. Is there a way to change my subscription option from digest to individual e-mails? I couldn't find any information on the list web page: https://mail.python.org/mailman/listinfo/python-list. At the bottom of that page is a button to "Unsubscribe or edit options". That's the one you want. TJG -- https://mail.python.org/mailman/listinfo/python-list
Re: What is heating the memory here? hashlib?
Às 22:45 de 13-02-2016, Chris Angelico escreveu: > On Sun, Feb 14, 2016 at 9:26 AM, Paulo da Silva > wrote: >> I meant eating! :-) > > Heh, "heating" works too - the more you use memory, the more it heats up :) :-) It is heating my head! ... > > What happens if, after hashing each file (and returning from this > function), you call gc.collect()? If that reduces your RAM usage, you > have reference cycles somewhere. > I have used gc and del. No luck. The most probable cause seems to be hashlib not correctly handling big buffers updates. I am working in a computer and testing in another. For the second part may be somehow I forgot to transfer the change to the other computer. Unlikely but possible. Anyway it is doing its job right now with bfsz=16KB (this takes a few hours). No memory leakages anymore. I'll address this problem in a near future, may be when I move to the new kubuntu 16.04 LTS. This will bring new SW releases and the problem may have been fixed. Thanks Paulo -- https://mail.python.org/mailman/listinfo/python-list
Re: What is heating the memory here? hashlib?
On Sun, Feb 14, 2016 at 12:44 PM, Paulo da Silva wrote: >> What happens if, after hashing each file (and returning from this >> function), you call gc.collect()? If that reduces your RAM usage, you >> have reference cycles somewhere. >> > I have used gc and del. No luck. > > The most probable cause seems to be hashlib not correctly handling big > buffers updates. I am working in a computer and testing in another. For > the second part may be somehow I forgot to transfer the change to the > other computer. Unlikely but possible. I'd like to see the problem boiled down to just the hashlib calls. Something like this: import hashlib data = b"*" * 4*1024*1024 lastdig = None while "simulating files": h = hashlib.sha256() hu = h.update for chunk in range(100): hu(data) dig = h.hexdigest() if lastdig is None: lastdig = dig print("Digest:",dig) else: if lastdig != dig: print("Digest fail!") Running this on my system (Python 3.6 on Debian Linux) produces a long-running process with stable memory usage, which is exactly what I'd expect. Even using different data doesn't change that: import hashlib import itertools byte = itertools.count() data = b"*" * 4*1024*1024 while "simulating files": h = hashlib.sha256() hu = h.update for chunk in range(100): hu(data + bytes([next(byte)&255])) dig = h.hexdigest() print("Digest:",dig) Somewhere between my code and yours is something that consumes all that memory. Can you neuter the actual disk reading (replacing it with constants, like this) and make a complete and shareable program that leaks all that memory? ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: What is heating the memory here? hashlib?
On Sun, 14 Feb 2016 06:29 am, Paulo da Silva wrote: > Hello all. > > I'm running in a very strange (for me at least) problem. > > def getHash(self): > bfsz=File.blksz > h=hashlib.sha256() > hu=h.update > with open(self.getPath(),'rb') as f: > f.seek(File.hdrsz)# Skip header > b=f.read(bfsz) > while len(b)>0: > hu(b) > b=f.read(bfsz) > fhash=h.digest() > return fhash This is a good, and tricky, question! Unfortunately, this sort of performance issue may depend on the specific details of your system. You can start by telling us what version of Python you are running. You've already said you're running on Kubuntu, which makes it Linux. Is that a 32-bit or 64-bit version? Next, let's see if we can simplify the code and make it runnable by anyone, in the spirit of http://www.sscce.org/ import hashlib K = 1024 M = 1024*K def get_hash(pathname, size): h = hashlib.sha256() with open(pathname, 'rb') as f: f.seek(4*K) b = f.read(size) while b: h.update(b) b = f.read(size) return h.digest() Does this simplified version demonstrate the same problem? What happens if you eliminate the actual hashing? def get_hash(pathname, size): with open(pathname, 'rb') as f: f.seek(4*K) b = f.read(size) while b: b = f.read(size) return "1234"*16 This may allow you to determine whether the problem lies in *reading* the files or *hashing* the files. Be warned: if you read from the same file over and over again, Linux will cache that file, and your tests will not reflect the behaviour when you read thousands of different files from disk rather than from memory cache. What sort of media are you reading from? - hard drive? - flash drive or USB stick? - solid state disk? - something else? They will all have different read characteristics. What happens when you call f.read(size)? By default, Python uses the following buffering strategy for binary files: * Binary files are buffered in fixed-size chunks; the size of the buffer is chosen using a heuristic trying to determine the underlying device's "block size" and falling back on `io.DEFAULT_BUFFER_SIZE`. On many systems, the buffer will typically be 4096 or 8192 bytes long. See help(open). That's your first clue that, perhaps, you should be reading in relatively small blocks, more like 4K than 4MB. Sure enough, a quick bit of googling shows that typically you should read from files in small-ish chunks, and that trying to read in large chunks is often counter-productive: https://duckduckgo.com/html/?q=file+read+buffer+size The first three links all talk about optimal sizes being measured in small multiples of 4K, not 40MB. You can try to increase the system buffer, by changing the "open" line to: with open(pathname, 'rb', buffering=40*M) as f: and see whether that helps. By the way, do you need a cryptographic checksum? sha256 is expensive to calculate. If all you are doing is trying to match files which could have the same content, you could use a cheaper hash, like md5 or even crc32. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
How do i instantiate a class_name passed via cmd line
I'm writing a price parser. I need to do the equivalent of perl's $$var to instantiate a class where $car is the class_name. I'm passing 'Ebay' or 'Newegg' or 'Amazon' via cmd-line. I have a module named ebay.py and a class called Ebay (price parser). I do something like: \> main.py ebay motherboard and this does: module = __import__(module_name) but now i need to instantiate the class - right now I do: instance = module.Ebay(module_name, product) how do i replace the 'Ebay' bit with a variable so that I can load any class via cmd line. class Load(object): def __init__(self, module_name, product): try: module = __import__(module_name) instance = module.Ebay(module_name, product) except ImportError: print("Can't find module %s" % module_name) -- https://mail.python.org/mailman/listinfo/python-list
Re: I cannot open IDLE
On Friday, February 12, 2016 at 7:06:45 AM UTC-6, anthony averett wrote: > I have downloaded python but I cannot open up idle. I really need this > issue resolved for I have work do for one of my computer science class. Sorry, but you failed to provide enough information. Here are a few possibilities: (1) Are you unaware of how to run the program, or need guidance as to it's location in the file hierarchy? or (2) Did you attempt to run the program, only to experience a crash or some sort of unexpected behavior? or (3) something else entirely... Please be more specific, and provide to us all the relevant specifications regarding your OS and Python versions. Thanks -- https://mail.python.org/mailman/listinfo/python-list
Re: How do i instantiate a class_name passed via cmd line
On Saturday, February 13, 2016 at 10:41:20 PM UTC-6, Veek. M wrote: > how do i replace the 'Ebay' bit with a variable so that I > can load any class via cmd line. Is this what you're trying to do? (Python2.x code) >>> import Tkinter as tk >>> classNames = ["Button", "Label"] >>> root = tk.Tk() >>> for className in classNames: classN = getattr(tk, className) instanceN = classN(root, text=className) instanceN.pack() Note: You won't need to call "mainloop" when testing this code on the command line, only in a script or in the IDLE shell. >>> root.mainloop() -- https://mail.python.org/mailman/listinfo/python-list
Re: How do i instantiate a class_name passed via cmd line
Rick Johnson wrote: > On Saturday, February 13, 2016 at 10:41:20 PM UTC-6, Veek. M wrote: >> how do i replace the 'Ebay' bit with a variable so that I >> can load any class via cmd line. > > Is this what you're trying to do? > > (Python2.x code) import Tkinter as tk classNames = ["Button", "Label"] root = tk.Tk() for className in classNames: > classN = getattr(tk, className) > instanceN = classN(root, text=className) > instanceN.pack() > > Note: You won't need to call "mainloop" when testing this > code on the command line, only in a script or in the IDLE > shell. > root.mainloop() Nope - this is what i'm doing: class Foo(): pass x = 'Foo' How do i use 'x' to create an instance of class Foo? -- https://mail.python.org/mailman/listinfo/python-list
Re: How do i instantiate a class_name passed via cmd line
Veek. M wrote: I'm writing a price parser. I need to do the equivalent of perl's $$var to instantiate a class where $car is the class_name. I'm passing 'Ebay' or 'Newegg' or 'Amazon' via cmd-line. I have a module named ebay.py and a class called Ebay (price parser). I do something like: \> main.py ebay motherboard and this does: module = __import__(module_name) but now i need to instantiate the class - right now I do: instance = module.Ebay(module_name, product) how do i replace the 'Ebay' bit with a variable so that I can load any class via cmd line. class Load(object): def __init__(self, module_name, product): try: module = __import__(module_name) instance = module.Ebay(module_name, product) except ImportError: print("Can't find module %s" % module_name) Something like this should do it: instance = getattr(module, class_name)(module_name, product) If the class name is always the same as the module name with the first letter capitalized, you could use instance = getattr(module, module_name.capitalize())(module_name, product) -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: How do i instantiate a class_name passed via cmd line
Gregory Ewing wrote: > Veek. M wrote: >> I'm writing a price parser. I need to do the equivalent of perl's >> $$var to instantiate a class where $car is the class_name. >> >> I'm passing 'Ebay' or 'Newegg' or 'Amazon' via cmd-line. I have a >> module named ebay.py and a class called Ebay (price parser). I do >> something like: >> >> \> main.py ebay motherboard >> >> and this does: >> module = __import__(module_name) >> but now i need to instantiate the class - right now I do: >> instance = module.Ebay(module_name, product) >> >> how do i replace the 'Ebay' bit with a variable so that I can load >> any class via cmd line. >> >> class Load(object): >> def __init__(self, module_name, product): >> try: >> module = __import__(module_name) >> instance = module.Ebay(module_name, product) >> except ImportError: >> print("Can't find module %s" % module_name) >> > > Something like this should do it: > >instance = getattr(module, class_name)(module_name, product) > > If the class name is always the same as the module name with the > first letter capitalized, you could use > >instance = getattr(module, module_name.capitalize())(module_name, >product) > Ah! i see - clever! 'getattr' returns the class object with class_name=whatever and we can instantiate now that we have a class object - nice - thanks guys - the bell should have rung from Rick's example. -- https://mail.python.org/mailman/listinfo/python-list
Re: How do i instantiate a class_name passed via cmd line
On 14Feb2016 10:10, Veek. M wrote: I'm writing a price parser. I need to do the equivalent of perl's $$var to instantiate a class where $car is the class_name. I'm passing 'Ebay' or 'Newegg' or 'Amazon' via cmd-line. I have a module named ebay.py and a class called Ebay (price parser). I do something like: \> main.py ebay motherboard and this does: module = __import__(module_name) but now i need to instantiate the class - right now I do: instance = module.Ebay(module_name, product) how do i replace the 'Ebay' bit with a variable so that I can load any class via cmd line. class Load(object): def __init__(self, module_name, product): try: module = __import__(module_name) instance = module.Ebay(module_name, product) except ImportError: print("Can't find module %s" % module_name) Ebay = geattr(module, 'Ebay') or klass = getattr(module, module_name.capitalize()) instance = klass(module_name, product) Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
Re: How do i instantiate a class_name passed via cmd line
On Saturday, February 13, 2016 at 11:39:56 PM UTC-6, Veek. M wrote: > Nope - this is what i'm doing: > > class Foo(): > pass > > x = 'Foo' > > How do i use 'x' to create an instance of class Foo? Use the builtin function `getattr` on the module that contains the class named "Foo". For example: module.Foo is equivelant to: getattr(module, "Foo") Here is an interactive session: py> import Tkinter py> Tkinter.Label py> getattr(Tkinter, "Label") -- https://mail.python.org/mailman/listinfo/python-list
Re: What is heating the memory here? hashlib?
I was unable to reproduce the situation using a simple program just walking through all files>4K, with or without the seek, and computing their shasums. Only some fluctuations of about 500MB in memory consumption. I'll look at this when I get more time, taking in consideration the suggestions here posted. For the time being, my work is done. With a small buffer size (16k) the results produced were correct and no memory was leaked! If I can find any explanation (if not embarrassing :-) ), I'll post it here. Thank you all. Paulo -- https://mail.python.org/mailman/listinfo/python-list