Re: [Tutor] Class vs. instance
On 18/01/12 02:13, Stayvoid wrote: class A: def __init__(self, data): self.data = data print self.data I'm trying to understand this function-like syntax: A('foo').__init__(42) You would not normally call any method with a double underscore pre/poist fix because they are special methods called by Python itself. Thus when you do A('foo') Python actually calls two special methods on class A. First it calls the __new__() method to create an instance of A then it calls __init__() with 'foo' as argument to initialise that instance. You don't need to call init() directly. In fact it may even cause problems if you initialise a class twice. So when you do A('foo').__init__(42) You actually do 3 things: First you create a new instance of A, then you initialise it with 'foo' then you initialise it again with 42. In this case no harm is done because the init)() method just does a double assignment, losing the initial value. But if you were storing the data values in a lkist you would wind up with two values instead of one, which may not be a good thing. A(12).data Here you create another instance of A and initialise it with 12 then you access its data attribute. If you do this in the interpreter the value of data will be printed, if you do it in a program nothing will happen. In both iof the cases above the newly created instances will be garbage collected since they were not assigned to any variable. What are we actually calling this way? You call the constructor __new__(), the initialiser __init__() and you access a data item which calls the accessor __getattr__() Are there any other ways to get the same result? It depends how you define 'the same results'. The same end state can be achieved in several ways. The same methods can be called in several ways, for example you can call init via the class: anAinstance = A('foo') A.__init__(anAinstance, 42) But in general all of these are a bad idea outside of a class/method definition. Don't do it. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Reg Ex Parentheses
On Wed, Jan 18, 2012 at 9:53 AM, Chris Kavanagh wrote: > Hey guys, girls, hope everyone is doing well. > > Here's my question, when using Regular Expressions, the docs say when using > parenthesis, it "captures" the data. This has got me confused (doesn't take > much), can someone explain this to me, please?? > > Here's an example to use. It's kinda long, so, if you'd rather provide your > own shorter ex, that'd be fine. Thanks for any help as always. > "Capturing" means that the part of the string that was matched is remembered, so you can extract parts of a string. Here's a small example that extracts the name and value part of a name=value style string. Note the use of parentheses, and the calls to the "group" method of the match object. the_string = 'A=B' pair_re = re.compile("""^ # starting from the start of the string ([^=]*) # sequence of characters not containing equals = # the literal equals sign (.*)# everything until... $ # end of string """, re.VERBOSE) match_obj = pair_re.match(the_string) print('Captured name was {}'.format(match_obj.group(1))) print('Captured value was {}'.format(match_obj.group(2))) -- regards, kushal ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
Help someone Trying to print to printer using python 3.2.2 Get error load dll error can't find win32print. It is in site library Thanks Selwyn ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
On Wed, Jan 18, 2012 at 6:00 AM, Selwyn Mileham wrote: > Help someone > > Trying to print to printer using python 3.2.2 > > Get error load dll error can’t find win32print. > > It is in site library > What have you tried? If you get an exception, please post the exact text of the traceback. If the code you used is short enough then it's reasonable to just paste it in your email (make sure HTML formatting is off, though, because it will probably break the formatting). -Wayne ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Facebook apps with python
Well, my question is simple.. How do I create facebook apps with python. I have couple of interesting/ funky programs and want to make them as apps. So, 1. What all things I should know for writing facebook apps. 2. I read that we should first upload our app to 'google app engine' and need do link it to facebook.. Is that right? 3. Actually, I am not aware of Network/ Web programming.. can I be able to do that? 4. Please do mention a couple of books (ebooks) from which I can learn.. That will help me. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Facebook apps with python
Please try this karthik https://www.google.com/search?client=ubuntu&channel=fs&q=how+to+create+facebook+app+using+python&ie=utf-8&oe=utf-8 On Wed, Jan 18, 2012 at 7:04 PM, karthik s wrote: > Well, my question is simple.. > > How do I create facebook apps with python. I have couple of interesting/ > funky programs and want to make them as apps. > > So, > > 1. What all things I should know for writing facebook apps. > > 2. I read that we should first upload our app to 'google app engine' and > need do link it to facebook.. Is that right? > > 3. Actually, I am not aware of Network/ Web programming.. can I be able to > do that? > > 4. Please do mention a couple of books (ebooks) from which I can learn.. > That will help me. > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > -- Cheers, Ranjith Kumar K, Chennai. http://ranjithtenz.wordpress.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
On 18/01/12 12:00, Selwyn Mileham wrote: Trying to print to printer using python 3.2.2 Get error load dll error can’t find win32print. So what are you trying? You don't give us much to work with here? Also you're more likely to get an answer from one of the Python windows lists rather than one dedicated to teaching the Python language. But without knowing how you are trying to print (wxPython, ctypes, pythonwin, other???) it's impossible to direct you to the best place. Can you show us a short piece of code that exhibits the problem and the full error trace? HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Facebook apps with python
On 18/01/12 13:34, karthik s wrote: Well, my question is simple.. How do I create facebook apps with python. I have no idea, I never use Facebook. But given this is a list for peiople learning the Python language it might be too specialised a question, you might be better on the general Python list. However, here goes a starting point... 1. What all things I should know for writing facebook apps. No idea on this one. 2. I read that we should first upload our app to 'google app engine' and need do link it to facebook.. Is that right? Do you know about the Google App Engine? Thats a whole topic in itself. You probbably need to visit Google and do some digging there. 3. Actually, I am not aware of Network/ Web programming.. can I be able to do that? You can do general network/web programming in Python. But if using Google is necessary then it's not going to be that standard... 4. Please do mention a couple of books (ebooks) from which I can learn.. That will help me. What is your starting point? Are you a complete beginner to programming? Can you program already in another language? Can you program already in Python? What OS and Python version are you using? -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] something about sum, integer and delta function
On Tue, Jan 17, 2012 at 10:25 AM, Lie Ryan wrote: > On 01/16/2012 12:57 AM, lina wrote: >> >> Hi, >> >> are there some modules can be used to do below things like: >> >> sum and delta function, and intergeration. > > > Are you trying to graphically render an equation, calculate the results of > equation, or algebraically manipulate the equation? It's involved a series of derivation process. a bit big project. I will come back later once my programming gets a bit mature. at present too heavy for me. Thanks all > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Installing Modules
Hello, I'll start by saying that I have a math/stats background, not a computer science one. I've found lots of great material to help with Python programming, but have had a much harder time getting my head around setup issues, like installing modules. I'm currently running Python version 2.7 through IDLE on a Windows machine. I'm trying to use numpy and scipy. I downloaded both modules from the scipy website and unzipped the files into: C:\Python27\Lib\site-packages I try to load them using this at the beginning of my program. from numpy import * from scipy import * And I get this error: Traceback (most recent call last): File "D:/Documents and Settings/pdowney/My Documents/Actual Projects/Foreclosures/Python/Program (1-18-12).py", line 3, in from scipy import * ImportError: No module named scipy Numpy loads just fine. Both are in the same folder. That is, there's a file called setup.py in the folder: C:\Python27\Lib\site-packages\numpy And also in the folder: C:\Python27\Lib\site-packages\scipy I don't understand what is being done differently between the two packages. According to Chapter 6 of the Python documentation, "When a module named spam is imported, the interpreter searches for a file named spam.py in the directory containing the input script and then in the list of directories specified by the environment variable PYTHONPATH." Unfortunately, I haven't figured out how to look at PYTHONPATH, so I don't know where it's looking. >>> print PYTHONPATH Traceback (most recent call last): File "", line 1, in print PYTHONPATH NameError: name 'PYTHONPATH' is not defined Importantly, there is no file scipy.py in the scipy folder, as the documentation suggests there should be, but there's also no numpy.py in the numpy folder and that module loads successfully. Clearly I'm missing something in the setup of these modules. Any guidance would be greatly appreciated. Thank you, Mitch ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Installing Modules
Have you looked at help(sys)? sys stores the PYTHONPATH variable. Just run >>> import sys >>> help(sys) at the python prompt. On 1/18/12, Downey, Patrick wrote: > Hello, > > I'll start by saying that I have a math/stats background, not a computer > science one. I've found lots of great material to help with Python > programming, but have had a much harder time getting my head around setup > issues, like installing modules. > > I'm currently running Python version 2.7 through IDLE on a Windows machine. > I'm trying to use numpy and scipy. I downloaded both modules from the scipy > website and unzipped the files into: > C:\Python27\Lib\site-packages > > I try to load them using this at the beginning of my program. > from numpy import * > from scipy import * > > And I get this error: > Traceback (most recent call last): > File "D:/Documents and Settings/pdowney/My Documents/Actual > Projects/Foreclosures/Python/Program (1-18-12).py", line 3, in > from scipy import * > ImportError: No module named scipy > > Numpy loads just fine. Both are in the same folder. That is, there's a file > called setup.py in the folder: > C:\Python27\Lib\site-packages\numpy > > And also in the folder: > C:\Python27\Lib\site-packages\scipy > > I don't understand what is being done differently between the two packages. > According to Chapter 6 of the Python documentation, "When a module named > spam is imported, the interpreter searches for a file named spam.py in the > directory containing the input script and then in the list of directories > specified by the environment variable PYTHONPATH." Unfortunately, I haven't > figured out how to look at PYTHONPATH, so I don't know where it's looking. print PYTHONPATH > Traceback (most recent call last): > File "", line 1, in > print PYTHONPATH > NameError: name 'PYTHONPATH' is not defined > > Importantly, there is no file scipy.py in the scipy folder, as the > documentation suggests there should be, but there's also no numpy.py in the > numpy folder and that module loads successfully. Clearly I'm missing > something in the setup of these modules. Any guidance would be greatly > appreciated. > > Thank you, > Mitch > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > -- My Blog - Defenestration Coding http://defenestrationcoding.wordpress.com/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Installing Modules
On 18/01/12 18:07, Downey, Patrick wrote: I'm trying to use numpy and scipy. I'll leave those specifics to those who use them, but... specified by the environment variable PYTHONPATH." Unfortunately, I haven't figured out how to look at PYTHONPATH, so I don't know where it's looking. Do it at the Windows level. The easiest way to see it is probably to start a CMD window and type SET PYTHONPATH at the C:\WINDOWS> (or whatever path it reads) prompt. You can also do it by: Assuming you are using Win2000 or XP you do that by right clicking My Computer and selecting Properties. Go to Advanced and click Environment Variables. Look for the PYTHONPATH one in the list and select it. Vista and Win7 might vary slightly... -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Installing Modules
On Wed, Jan 18, 2012 at 1:07 PM, Downey, Patrick wrote: > I'm currently running Python version 2.7 through IDLE on a Windows machine. > I'm trying to use numpy and scipy. I downloaded both modules from the scipy > website and unzipped the files into: > C:\Python27\Lib\site-packages > That is not the typical way to install software on windows, even python modules. Typically, software on windows is distributed in an installer. Numpy and Scipy are the same way. You could download the source code, compile it, and install it from there, but that's pretty unusual on windows. So. Remove whatever you have unzipped into site-packages. Download the numpy and scipy installers. Run them. That should be it. Numpy installer: http://sourceforge.net/projects/numpy/files/NumPy/1.6.1/numpy-1.6.1-win32-superpack-python2.7.exe/download Scipy installer: http://sourceforge.net/projects/scipy/files/scipy/0.10.0/scipy-0.10.0-win32-superpack-python2.7.exe/download If you really do want to compile scipy and numpy from source, there are instructions on getting all the required tools here: http://scipy.org/Installing_SciPy/Windows -- Jerry PS: There *are* python packages out there that have to just be unzipped into site-packages. Those projects are typically pure-python modules without any C code to compile. Numpy and Scipy aren't among them, though. There are other packages that expect you to download them, extract them to a temp directory, then run "python setup.py install". To know for sure how to install a particular package, you'll need to dig around a bit for installation instructions for that particular package. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Installing Modules
Hi, On 18 January 2012 18:07, Downey, Patrick wrote: > I'm currently running Python version 2.7 through IDLE on a Windows machine. > I'm trying to use numpy and scipy. I downloaded both modules from the scipy > website and unzipped the files into: > C:\Python27\Lib\site-packages > Generally, manually installing modules/packages into site-packages should be the last option you choose for installing 3rd party modules/packages into your Python environment. For Windows machines, you should, in order of preference (IMHO) choose: 1.) A customer installer package (.exe. file or .msi file) built for your specific bit version of Windows (ie 32 or 64 bit) and for your specific version of Python (e.g. 2.7, 3.2 etc.) 2.) Install via Python's generic package management support e.g. via one of: distribute pip setuptools These tools make it trivial to install most non-platform-specific modules from a central repository using a single command, removing the need to know where to get them or how to install them. 3.) Direct installation via an included "setup.py" script: Most Python packages include an installation script intended to install the package into your Python environment correctly, usually via the command: python setup.py install 4.) Manually copying/installing into your Python environment. In your case, there are Windows .exe based installers available for Windows 32 bit for Python 2.7 for both SciPy and NumPy so I'd suggest you remove your manual attempts and re-install using one of the pre-built installers. HTH, Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] To: Wayne Werner , re Reg. Expressions Parenthesis
For some reason I didn't get this email, found it in the archives. I wanted to make sure I thanked Wayne for the help!!! On Tue, Jan 17, 2012 at 3:07 AM, Chris Kavanagh <[hidden email]> wrote: Hey guys, girls, hope everyone is doing well. Here's my question, when using Regular Expressions, the docs say when using parenthesis, it "captures" the data. This has got me confused (doesn't take much), can someone explain this to me, please?? Here's an example to use. It's kinda long, so, if you'd rather provide your own shorter ex, that'd be fine. Thanks for any help as always. Here's a quick example: import re data = 'Wayne Werner fake-phone: 501-555-1234, fake-SSN: 123-12-1234' parsed = re.search('([\d]{3})-([\d]{3}-[\d]{4})', data) print(parsed.group()) print(parsed.groups()) parsed = re.search('[\d]{3}-[\d]{3}-[\d]{4}', data) print(parsed.group()) print(parsed.groups()) You'll notice that you can access the individual clusters using the .groups() method. This makes capturing the individual groups pretty easy. Of course, capturing isn't just for storing the results. You can also use the captured group later on. Let's say, for some fictitious reason you want to find every letter that appears as a double in some data. If you were to do this the "brute force" way you'd pretty much have to do something like this: for i in range(len(data)-1): found = [] if data[i] == data[i+1]: if not data[i] in found: found.append(i) print(found) The regex OTOH looks like this: In [29]: data = 'aaabababbcacacceadbacdb' In [32]: parsed = re.findall(r'([a-z])\1', data) In [33]: parsed Out[33]: ['a', 'b', 'c'] Now, that example was super contrived and also simple. Very few real-world applications will be as simple as that one - usually you have much crazier specifications, like find every person who has blue eyes AND blue hair, but only if they're left handed. Assuming you had data that looked like this: NameEye ColorHair Color Handedness Favorite type of potato WayneBlue BrownDexter Mashed Sarah Blue Blonde SinisterSpam(?) Kane Green White Dexter None Kermit Blue Blue SinisterIdaho You could parse out the data using captures and backrefrences [1]. HTH, Wayne [1] In this situation, of course, regex is overkill. It's easier to just .split() and compare. But if you're parsing something really nasty like EDI then sometimes a regex is just the best way to go[2]. [2] When people start to understand regexes they're like the proverbial man who only has a hammer. As Jamie Zawinski said[3], "Some people, when confronted with a problem, think “I know, I'll use regular expressions.” Now they have two problems." I've come across very few occasions that regexes were actually useful, and it's usually extracting very specifically formatted data (money, phone numbers, etc.) from copious amounts of text. I've not yet had a need to actually process words with it. Especially using Python. [3]http://regex.info/blog/2006-09-15/247 ___ Tutor maillist - [hidden email] To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Thanks again Wayne. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Question about install.py
Hello, I'm new to Python and was wondering if someone could answer a question I have. Say that I have a python library, arithmetic-0.5, located at /X/arithmetic-0.5 I'd like to run setup and install it. But I guess since /X/arithmetic-0.5 is not in install.py's default search path, it comes back with an error saying that it cannot find the necessary files. Can you please tell me how I can change the search path of install.py? What parameter do I need to modify? Thanks in advance. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor