Re: [Tutor] Help with class example
On 10/18/2012 07:59 PM, Frank Pontius wrote: Hello, I'm taking a beginners course on Python. Have class example which is to be used in H/W, which I can't get to work. Thus I figure the example is wrong. But I need this to get H/W done. Using 'import random' and random.randrange in function, returning #. import random def RandomNumberGen (): if random.randrange(0, 2) == 0: Xreturn tails return heads Simple enough, but running in my Python 2.7.3 IDLE - it will not even run, and give syntax (red char box) error at the X above. Frank So why is there an X there? As the compiler tells you, that's a syntax error. The return statement starts with an 'r' Please use only text editors to edit code, and use copy/paste to copy the actual source to your message, while composing the message in text mode. We cannot tell who has mangled the code, but only how it happens to look after the mangling is finished. If it ever goes through a word processor, or through an html message (which your is), then all bets are off. Another thing. Copy/paste the actual error message, including the traceback. Don't summarize it, or paraphrase it. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help on Remote File Copy Exection
Hi All, First of the big thanks and congrats for managing such a brilliant online community. I am new to Python and have started getting the taste of python on my day to day work. I have a requirement and i am trying to solve it using python. I am from QA. Here is what i do daily and wanted to do with python automatically. 1. Revert the snapshot of a VM used for testing. - i have automated using pysphere 2. Copy the build from share location to the VM - here i can have a python script run from the VM but is it possible to run it remotely? for example. if i run the script from Machine A, it should revert the snapshot of machine B and copy the build to Machine B from shared location. 3. Run the installer and clikc Next Button of the installation GUI. - Any idea how to automate this ? Regards, Aru ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help on Remote File Copy Exection
On 25 October 2012 10:26, Arumugam N aru1...@gmail.com wrote: Hi All, First of the big thanks and congrats for managing such a brilliant online community. I am new to Python and have started getting the taste of python on my day to day work. I have a requirement and i am trying to solve it using python. I am from QA. Here is what i do daily and wanted to do with python automatically. 1. Revert the snapshot of a VM used for testing. - i have automated using pysphere 2. Copy the build from share location to the VM - here i can have a python script run from the VM but is it possible to run it remotely? for example. if i run the script from Machine A, it should revert the snapshot of machine B and copy the build to Machine B from shared location. 3. Run the installer and clikc Next Button of the installation GUI. - Any idea how to automate this ? These questions are probably more suited to a different mailing list as this one is predominantly for helping in learning the elementary aspects of programming in Python. If you can perhaps ask a more specific Python question it might be appropriate here. Otherwise I suggest that you either: a) Ask on the pysphere mailing list (I have no idea what pysphere is so this may not be appropriate) b) Use a search engine to find a project that already does what you want c) Ask for general help on python-list where people may know of a good way to do what you want in Python Oscar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help on Remote File Copy Exection
On 25/10/12 10:26, Arumugam N wrote: 1. Revert the snapshot of a VM used for testing. - i have automated using pysphere 2. Copy the build from share location to the VM - here i can have a python script run from the VM but is it possible to run it remotely? for example. if i run the script from Machine A, it should revert the snapshot of machine B and copy the build to Machine B from shared location. This should be possible using the same commands you'd use if done from a command line. Or if the VM is accessible via the network you might be able to do it that way. But given we have no information about the environment - what OS, what VM etc? Its impossible to say. Its also a bit off the normal topics for the tutor lkist 3. Run the installer and clikc Next Button of the installation GUI. - Any idea how to automate this ? subprocess can probably run the installer, clicking a GUI button will depend on the OS. For example in windows you could use ctypes to access the win32 API to send a mouse click message to the installer app... not trivial, but not impossible either. No idea how you'd do it on *nix or MacOS. -- 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] Help on Remote File Copy Exection
Arumugam N wrote: Hi All, First of the big thanks and congrats for managing such a brilliant online community. I am new to Python and have started getting the taste of python on my day to day work. I have a requirement and i am trying to solve it using python. I am from QA. Here is what i do daily and wanted to do with python automatically. 1. Revert the snapshot of a VM used for testing. - i have automated using pysphere I would ask this on the pysphere discussion group: https://groups.google.com/forum/?fromgroups#!forum/pysphere 2. Copy the build from share location to the VM - here i can have a python script run from the VM but is it possible to run it remotely? for example. if i run the script from Machine A, it should revert the snapshot of machine B and copy the build to Machine B from shared location. You should be able to handle file transfer through some libraries, but it depends on the OSes involved and how they are setup. You can always transfer via FTP or SSH. If Machine B is a *nix box, you can SSH in with Paramiko and then use scp/sftp/rsync to transfer and run commands to restart the VM on machine B. 3. Run the installer and clikc Next Button of the installation GUI. - Any idea how to automate this ? No idea, sorry. Regards, Aru This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help - Using Sort and Join
Hi Python Tutor, I have an issue trying to figure out how to print out final answers using sort and join functions. Assignment Specification: make a function that is a magic eight ball emulator. emulator will be a function that returns one of the possible answers. Make another function that runs the emulator over and over again until user wants to quit, printing answer each time. When user quits, present all answers that the user got again, but present them in alphabetical order. Use the join() function available for strings for this. Below is an example output from my code: ask a question (or press 'enter' to quit): will I be rich You may rely on it. ask a question (or press 'enter' to quit): will I be poor It is decidedly so. ask a question (or press 'enter' to quit): why is that Better not tell you now. As my code is written when user presses enter I simply break and print this current output: Have a nice day What I want is when user exits for my code to take all previous answers, joining them and sorting them like below: ask a question (or press 'enter' to quit): You may rely on it. It is decidedly so. Better not tell you now. My code works right now but I am missing the final part in how to join and sort all answers. Any suggestions or examples is helpful as I am very new with Python. Current code is attached for viewing. Thanks, Dan import random def AskMagicEightBall(): answers = (As I see it, yes., It is certain., It is decidedly so., Most likely., Outlook good., Signs point to yes., Without a doubt., Yes., Yes definitely., You may rely on it., Reply hazy, try again., Ask again later., Better not tell you now., Do not count on it., My reply is no., My sources say no., Outlook not so good., Very doubtful.) return random.choice(answers) def RunEmulator(): while True: question = raw_input(ask a question (or press 'enter' to quit): ) if question: answers=AskMagicEightBall() print answers elif not question: print Have a nice day break RunEmulator() ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help - Using Sort and Join
On 10/22/2012 03:57 PM, Daniel Gulko wrote: Hi Python Tutor, I have an issue trying to figure out how to print out final answers using sort and join functions. Assignment Specification: make a function that is a magic eight ball emulator. emulator will be a function that returns one of the possible answers. Make another function that runs the emulator over and over again until user wants to quit, printing answer each time. When user quits, present all answers that the user got again, but present them in alphabetical order. Use the join() function available for strings for this. Below is an example output from my code: ask a question (or press 'enter' to quit): will I be rich You may rely on it. ask a question (or press 'enter' to quit): will I be poor It is decidedly so. ask a question (or press 'enter' to quit): why is that Better not tell you now. As my code is written when user presses enter I simply break and print this current output: Have a nice day What I want is when user exits for my code to take all previous answers, joining them and sorting them like below: ask a question (or press 'enter' to quit): You may rely on it. It is decidedly so. Better not tell you now. My code works right now but I am missing the final part in how to join and sort all answers. Any suggestions or examples is helpful as I am very new with Python. Current code is attached for viewing. Thanks, Dan You should assume that people cannot get an attachment. Some can and some cannot. Just put the code inline, and make sure you're writing a text message. (Your current one is html, another flaw that can cause some to not get it the way you sent it) Anyway, if you want to present a summary at the end, you'll have to build a list as you go. At the beginning of your function, create an empty list. Then append to it each message you're outputting. Then when you fall out of the loop, you can manipulate that list as your assignment says, first sorting it, then using join to create a single string from the list. Also, you don't need an elif, since you already know the condition there will be true. Just use if and else, and just use a break under else. Then outside the loop, you can do as much as you like to give the final information. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help - Using Sort and Join
On 22 October 2012 20:57, Daniel Gulko dangu...@hotmail.com wrote: Hi Python Tutor, Hi Daniel, I have an issue trying to figure out how to print out final answers using sort and join functions. Do you know how to use sort and join to print a list of strings in alphabetical order? Assignment Specification: make a function that is a magic eight ball emulator. emulator will be a function that returns one of the possible answers. Make another function that runs the emulator over and over again until user wants to quit, printing answer each time. When user quits, present all answers that the user got again, but present them in alphabetical order. Use the join() function available for strings for this. As my code is written when user presses enter I simply break and print this current output: Have a nice day What I want is when user exits for my code to take all previous answers, joining them and sorting them like below: ask a question (or press 'enter' to quit): You may rely on it. It is decidedly so. Better not tell you now. The problem is that your not saving the answers so at the point where your program ends they aren't available for you to print them. You should use a list to collect the answers as they are generated. Then you can think about how to use the sort and join functions My code works right now but I am missing the final part in how to join and sort all answers. Any suggestions or examples is helpful as I am very new with Python. Current code is attached for viewing. Your code is not too long to be pasted directly into the email: ''' import random def AskMagicEightBall(): answers = (As I see it, yes., It is certain., It is decidedly so., Most likely., Outlook good., Signs point to yes., Without a doubt., Yes., Yes – definitely., You may rely on it., Reply hazy, try again., Ask again later., Better not tell you now., Do not count on it., My reply is no., My sources say no., Outlook not so good., Very doubtful.) return random.choice(answers) def RunEmulator(): while True: question = raw_input(ask a question (or press 'enter' to quit): ) if question: answers=AskMagicEightBall() print answers elif not question: print Have a nice day break RunEmulator() ''' Oscar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help Passing Variables
Thanks David. This has been helpful in understanding a bit more on how parameters are passed through. Date: Thu, 18 Oct 2012 04:44:55 -0400 Subject: Re: [Tutor] Help Passing Variables From: dwightdhu...@gmail.com To: dangu...@hotmail.com CC: tutor@python.org #A little more complex in terms of params: def SwapCaseAndCenter(*kwargs): if upper_or_lower == upper: print a_string.center(center_num).upper() if upper_or_lower == lower: print a_string.center(center_num).lower() a_string = raw_input(Give me a word, or letter: ) upper_or_lower = raw_input(upper, or lower character(s): ) center_num = int(raw_input(Where should number be centered?: )) SwapCaseAndCenter(a_string, upper_or_lower, center_num) -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help Passing Variables
On 10/19/2012 11:40 AM, Daniel Gulko wrote: Thanks David. This has been helpful in understanding a bit more on how parameters are passed through. Please don't top-post. it ruins the sequence of events. Your comments above happened after the parts you quote below. So why are they not after the things they follow? There is a long-standing convention in this forum, and many others, and why let Microsoft ruin it for all of us? Date: Thu, 18 Oct 2012 04:44:55 -0400 Subject: Re: [Tutor] Help Passing Variables From: dwightdhu...@gmail.com To: dangu...@hotmail.com CC: tutor@python.org #A little more complex in terms of params: def SwapCaseAndCenter(*kwargs): By convention kwargs is used for keyword arguments, while the * means positional arguments. The function uses none of them, so it's all bogus. You can't learn anything useful about argument passing from this example code, except what NOT to do. if upper_or_lower == upper: print a_string.center(center_num).upper() if upper_or_lower == lower: print a_string.center(center_num).lower() To understand the most elementary aspects of function passing, let's write a whole new function, and call it a few times. Paste this into a file, and try various things, and make sure you see how they work. Or reread Alan's email, which was also correct and clear. First point, a simple function may take zero arguments, or one, or two, or fifty. We'll start with positional arguments, which means order matters. Python also supports keyword arguments, default values, and methods, none of which I'll cover here. When you define a function, you specify its formal parameters. You do that by putting the parameter names inside the parentheses. Unlike most languages, you do NOT specify the types of any of these. But the order matters, and the number matters. So if we define a function: def truncate_string(a_string, width): temp = a_string[:width] return temp That function needs to be called with two arguments, which match the two formal parameters. They do NOT have to have the same names, and in fact they might well be literal strings or ints, or variables with string and int values. print truncate_string(this is a long string, 4) should print out this (without the quotes, of course) name = raw_input(give me a name) trunc_name = truncate_string(name, 8) print trunc_name truncate_string(aaa) #gives error, because it has the wrong number of arguments Does this help? -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help Passing Variables
Hi Python Tutor, I have a write a simple function named SwapCaseAndCenter(a_string, width). The idea is to use the function swapcase and center so that when the userenters a string it centers it and swaps the case (e.g. upper to lower and vice versa). The function calls for passing in two variables a_string, width but I am still confused on this concept. In my code below I seem to be able to pass in the variable a_string and found out how to use the center along with swapcase functions. I am still unsure howto pass in the variable width. In my code I have hard coded the centering but I am not sure if instead I use the variable width to determine the centering. Any suggestions, help or examples of how to do this is appreciated. def SwapCaseAndCenter(a_string):while True: a_string=raw_input(give me a word: (enter to quit): ) if a_string: print a_string.center(60).swapcase() elif not a_string: print you did not provide a word. goodbye break SwapCaseAndCenter(a_string) Thanks, Dan ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help Passing Variables
On 18/10/12 08:08, Daniel Gulko wrote: The function calls for passing in two variables a_string, width but I am still confused on this concept. You just provide the list of input parameters when you define the function: def add(x,y): ... return x+y ... add(4,5) 9 I define add to take two parameters x and y. I then supply two corresponding arguments, 4,5 when I call add. I then use x and y inside my function (x+y) like ordinary variables. am still unsure how to pass in the variable width. add it to your function definition as I did for add() Then add a width value to the call to your function centering but I am not sure if instead I use the variable width to determine the centering. Yes, or being pedantic, you use the parameter 'width' in your call to centre() def SwapCaseAndCenter(a_string): while True: a_string=raw_input(give me a word: (enter to quit): ) if a_string: print a_string.center(60).swapcase() elif not a_string: print you did not provide a word. goodbye break BTW putting break here means your loop only ever executes once. Frankly I would take the loop out and prompt the user for a_string outside the function and pass the string in along with the width. I'd also return the modified string so the caller can print it. Also rather than use the elif line I'd change it to an else. The test is implied by the fact it failed the initial if test. Either a_string is True (it exists) or it is not True, there is no third option so you don't need a separate elif test. If you really want to prompt the user multiple times do that outside the function: while True: my_string=raw_input(give me a word: (enter to quit): ) if my_string: print SwapCaseAndCenter(my_string,60) else: print you did not provide a word. goodbye break 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] Help Passing Variables
On 10/18/2012 03:08 AM, Daniel Gulko wrote: Hi Python Tutor, I have a write a simple function named SwapCaseAndCenter(a_string, width). So why did you define it with only one formal parameter? The idea is to use the function swapcase and center so that when the userenters a string it centers it and swaps the case (e.g. upper to lower and vice versa). The function calls for passing in two variables a_string, width but I am still confused on this concept. In my code below I seem to be able to pass in the variable a_string and found out how to use the center along with swapcase functions. I am still unsure howto pass in the variable width. In my code I have hard coded the centering but I am not sure if instead I use the variable width to determine the centering. Any suggestions, help or examples of how to do this is appreciated. def SwapCaseAndCenter(a_string):while True: As you can see, your email program thoroughly messed up this source code. Please send your messages in text form, as html frequently gets trashed as it goes through various gateways. This is a text-mailing list. a_string=raw_input(give me a word: (enter to quit): ) Why do you ask the user for the input, when it was already supplied as a parameter? it's best practice to separate input from calculation, and your teacher had done that in his/her specification. if a_string: print a_string.center(60).swapcase() elif not a_string: print you did not provide a word. goodbye Presumably you should be returning the centered/swapped string. No idea where the following break is supposed to happen. But once you eliminate the raw_input, you'll be eliminating the while True and the break. break SwapCaseAndCenter(a_string) Thanks, Dan -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help for Python Beginner with extracting and manipulating data from thousands of ASCII files
Hi Cecilia, I'm sending this again as the first message was sent only to you (I hadn't realised that your own message was sent only to me as well). If you want to reply please reply-all to this message. On 1 October 2012 17:42, Cecilia Chavana-Bryant cecilia.chav...@gmail.com wrote: On Mon, Oct 1, 2012 at 11:02 AM, Oscar Benjamin oscar.j.benja...@gmail.com wrote: On Sep 30, 2012 11:10 PM, Cecilia Chavana-Bryant cecilia.chav...@gmail.com wrote: fileDate = data[6][16:26] # location of the creation date on the data files What format does fileDate have? I guess it's a string of text from the file. If you can convert it to a datetime (or date) object it will be easy to compare with the dates as required for your calibration file. Can you show us how it looks e.g. '12-Nov-2012' or '12/11/12' or something else? Date is in the following format: dd/mm/ The standard way to work with dates is to turn the date strings into Python datetime objects. You can read about those here: http://docs.python.org/library/datetime.html datetime objects can be create directly: from datetime import datetime start_date = datetime(year=2012, month=11, day=3) print start_date 2012-11-03 00:00:00 You can also create them from a string: datestring = '10/11/2012' experiment_date = datetime.strptime(datestring, '%d/%m/%Y') print experiment_date 2012-11-10 00:00:00 Once you have two datetime objects you can compare them directly: experiment_date start_date True print experiment_date - start_date 7 days, 0:00:00 Using this you can check whether the date from the data file is in between the start and end dates for each of the calibration files and then choose which calibration file to use. Oscar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help for Python Beginner with extracting and manipulating data from thousands of ASCII files
On Sep 30, 2012 11:10 PM, Cecilia Chavana-Bryant cecilia.chav...@gmail.com wrote: Hola again Python Tutor! Hi Cecilia With a friend's help I have the following code to extract reflectance data from an ASCII data file, do a bit of data manipulation to calibrate the data and then write the calibrated file into an out file. import numpy # import glob - use if list_of_files is used dataFile = 1SH0109.001.txt #list_of_files = glob.glob('./*.txt') to replace dataFile to search for all text files in ASCII_files folder? caliFile1 = Cal_File_P17.txt # calibration file to be used on data files created from July to 18 Sep caliFile2 = Cal_File_P19.txt # calibration file to be used on data files created from 19 Sep onwards outFile = Cal_ + dataFile # this will need to change if list_of_files is used fileDate = data[6][16:26] # location of the creation date on the data files The variable data used in the line above is not created until the lines below run. I think you need to move this line down. What format does fileDate have? I guess it's a string of text from the file. If you can convert it to a datetime (or date) object it will be easy to compare with the dates as required for your calibration file. Can you show us how it looks e.g. '12-Nov-2012' or '12/11/12' or something else? #extract data from data file fdData = open(dataFile,rt) data = fdData.readlines() fdData.close() Python has a slightly better way of writing code like this: with open(dataFile, 'rt') as fdata: data = fdata.readlines() This way you don't need to remember to close the file. In fact Python will even remember to close it if there is an error. #extract data from calibration file fdCal = open(caliFile,rt) calibration = fdCal.readlines() fdCal.close() Where is caliFile set? If your going to load all the data files you might as well load both calibration files here at the beginning. #create data table k=0 #just a counter dataNum = numpy.ndarray((2151,2)) Does dataNum store integers or floating point numbers? Numpy won't let you do both in the same array. You should always specify the type of the numpy array that you want to create: dataNum = numpy.ndarray((2152, 2), float) or dataNum = numpy.ndarray((2152, 2), int) As it happens you are creating an array floats. That means that when you try to store an integer in the array below it gets converted to a float. #the actual data (the numbers) in the data file begin at line 30 for anItem in data[30:]: theNums = anItem.replace(\r\n,).split(\t) dataNum[k,0] = int(theNums[0]) dataNum[k,1] = float(theNums[1]) k+=1 #advance the counter You should look into using numpy.fromfile. This function is specifically designed for this purpose. For example: with open(dataFile) as fdata: header_lines = [fdata.readline() for _ in range(30)] dataNum = numpy.fromfile(fdata, float, sep='\t') Oscar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help for Python Beginner with extracting and manipulating data from thousands of ASCII files
On Mon, Oct 1, 2012 at 12:33 AM, Alan Gauld alan.ga...@btinternet.comwrote: On 30/09/12 23:07, Cecilia Chavana-Bryant wrote: Hola again Python Tutor! With a friend's help I have the following code to extract reflectance data from an ASCII data file, do a bit of data manipulation to calibrate the data and then write the calibrated file into an out file. snip I have successfully calibrated one ASCII file at a time with this code. However, I have 1,000s of files that I need to calibrate so I would like some help to modify this code so it can: 1. Use one calibration file (Cal_FileP17.txt) on data files created from July to the 18th Sep and a different calibration file (Cal_FileP19.txt) for data files created from the 19th of Sep onwards. 2. Find all the .txt files in a folder called ASCII_files, which is subdivided into 12 different folders and calibrate all these files Number 2 is easier to solve and the os.walk() and glob.glob() functions should provide all the tools you need. Number 1 is more tricky since there is no obvious way to determine the arbitrary start/stop dates you specify. So I'd suggest you need to generalise the requirement to take a start/stop date as well as the calibration file name and the input data file pattern. Use those as input parameters to a function that generates the list of files to process and then calls your existing code (wrapped in a new function) and possibly provide default values for all/some of the parameters. Another option is to add the start/end dates to the calibration file if you have control of that, but personally I'd stick with input parameters... Many thanks Alan for your reply. I have added start and end dates as part of the header information for the calibration files in the date format: 01/07/2011. So, I now need to write some code to take this into consideration, any suggestions? -- 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/tutorhttp://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help for Python Beginner with extracting and manipulating data from thousands of ASCII files
On Mon, Oct 1, 2012 at 1:16 AM, Dave Angel d...@davea.name wrote: On 09/30/2012 06:07 PM, Cecilia Chavana-Bryant wrote: Hola again Python Tutor! With a friend's help I have the following code to extract reflectance data from an ASCII data file, do a bit of data manipulation to calibrate the data and then write the calibrated file into an out file. import numpy # import glob - use if list_of_files is used dataFile = 1SH0109.001.txt #list_of_files = glob.glob('./*.txt') to replace dataFile to search for all text files in ASCII_files folder? First, an important observation. This code has no functions defined in it. Thus it's not reusable. So every time you make a change, you'll be breaking the existing code and then trying to make the new version work. The decision of one file versus many is usually handled by writing a function that deals with one file. Test it with a single file. Then write another function that uses glob to build a list of files, and call the original one in a loop. As you work on it, you should discover that there are a half dozen other functions that you need, rather than one big one. Many thanks for this advise this helps me to get started with trying to write functions for the different procedures and then think about many files. caliFile1 = Cal_File_P17.txt # calibration file to be used on data files created from July to 18 Sep caliFile2 = Cal_File_P19.txt # calibration file to be used on data files created from 19 Sep onwards outFile = Cal_ + dataFile # this will need to change if list_of_files is used fileDate = data[6][16:26] # location of the creation date on the data files Show us the full traceback from the runtime error you get on this line. The option of using 2 different calibration files is an idea that I haven't tested yet as I am a bit lost in how to do this. I have gotten as far as adding start and end dates on both calibration files as part of the header information for each file. #extract data from data file fdData = open(dataFile,rt) data = fdData.readlines() fdData.close() #extract data from calibration file fdCal = open(caliFile,rt) Show us the full traceback from the runtime error here, as well. In the original code which uses only one calibration file this and the rest of the code works without error. calibration = fdCal.readlines() fdCal.close() #create data table k=0 #just a counter dataNum = numpy.ndarray((2151,2)) #the actual data (the numbers) in the data file begin at line 30 for anItem in data[30:]: theNums = anItem.replace(\r\n,).split(\t) dataNum[k,0] = int(theNums[0]) dataNum[k,1] = float(theNums[1]) k+=1 #advance the counter #create the calibration table k = 0 calNum = numpy.ndarray((2151,2)) for anItem in calibration[5:]: theNums = anItem.replace(\r\n,).split(\t) calNum[k,0] = int(theNums[0]) calNum[k,1] = float(theNums[1]) k+=1 #calibrate the data k=0 calibratedData = numpy.ndarray((2151,2)) for aNum in dataNum: calibratedData[k,0] = aNum[0] #first column is the wavelength calibratedData[k,1] = (aNum[1] * dataNum[k,1]) * 100.0 #second column is the measurement to be calibrated. k+=1 #write the calibrated data fd = open(outFile,wt) Error traceback ? #prior to writing the calibrated contents, write the headers for data files and calibration files fd.writelines(data[0:30]) fd.writelines(calibration[0:5]) for aNum in calibratedData: #Write the data in the file in the following format: # An integer with 3 digits, tab character, Floating point number fd.write(%03d\t%f\n % (aNum[0],aNum[1])) #close the file fd.close() Are the individual files small? By doing readlines() on them, you're assuming you can hold all of both the data file and the calibration file in memory. Both the calibration and the data files are small. The original excel calibration files have been saved as Tab delimited text files and the data files are ASCII files with 2151 rows and 2 columns. I have successfully calibrated one ASCII file at a time with this code. Unless I'm missing something, this code does not run. I didn't try it, though, just inspected it quickly. However, I have 1,000s of files that I need to calibrate so I would like some help to modify this code so it can: 1. Use one calibration file (Cal_FileP17.txt) on data files created from July to the 18th Sep and a different calibration file (Cal_FileP19.txt) for data files created from the 19th of Sep onwards. 2. Find all the .txt files in a folder called ASCII_files, which is subdivided into 12 different folders and calibrate all these files I have googled and tried thinking about how to make changes and I've managed to get myself a bit more confused. Thus, I would like some guidance on how to tackle/think about this process and how to get started.
[Tutor] HELP!
hello, I am a college student in my first year of computer programming, I was wondering if you could look at my code to see whats wrong with it. # Mark Rourke # Sept 29, 2012 # Write a program to calculate the sales tax at the rate of 4% and 2% respectively # Thereafter compute the total sales tax (sum of the state tax and the county tax) # and the total purchase amount (sum of the purchase amount and the total sales tax). # Finally, display the amount of purchase, the state sales tax, the county sales tax, #the total sales tax and the total amount of the sale. #Variable Declarations #Real purchaseAmount, stateSalesTax, countySalesTax, totalSalesTax, totalPurchaseAmount #Constant Real SALES_TAX = 0.4, COUNTY_TAX = 0.02 #Display Input Purchase Amount: $ #input the hours worked and hourly wage wage SALES_TAX = 0.4 COUNTY_TAX = 0.02 print(--) print((This program calculates the sales tax at the rate of 4% and 2% respectively, as well sum of the state tax)) print(--) purchaseAmount = input(Please input the Purchase Amount: $) #Calculate the State Sales Tax, County Sales Tax, Total Sales Tax, Total Purchase Amount purchaseAmount = int(purchaseAmount) stateSalesTax = int(purchaseAmount * SALES_TAX) countySalesTax = int(purchaseAmount * COUNTY_TAX) totalSalesTax = int(stateSalesTax + countySalesTax) totalPurchaseAmount = int(purchaseAmount + totalSalesTax) #Output the results Display (Purchase Amount:$) purchaseAmount Display (The State Sales Tax $) SALES_TAX Display (The County Sales Tax: $) COUNTY_TAX Display (The Total Sales Tax: $) totalSalesTax Display (The Total Amount of the Purchase: $) totalPurchaseAmount -- Mark Rourke T: 705-728-6169 M: 705-331-0175 E: mark.rour...@gmail.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] HELP!
Is the only problem that your code is giving unexpected results, or that it doesnt run or what? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] HELP!
On 1 Oct 2012 19:58, Mark Rourke mark.rour...@gmail.com wrote: hello, I am a college student in my first year of computer programming, I was wondering if you could look at my code to see whats wrong with it. # Mark Rourke # Sept 29, 2012 # Write a program to calculate the sales tax at the rate of 4% and 2% respectively # Thereafter compute the total sales tax (sum of the state tax and the county tax) # and the total purchase amount (sum of the purchase amount and the total sales tax). snip SALES_TAX = 0.4 COUNTY_TAX = 0.02 snip purchaseAmount = input(Please input the Purchase Amount: $) #Calculate the State Sales Tax, County Sales Tax, Total Sales Tax, Total Purchase Amount purchaseAmount = int(purchaseAmount) stateSalesTax = int(purchaseAmount * SALES_TAX) snip Hi Mark, c smith is certainly right to suggest that you ought to specify a bit more about what the symptoms are that you would like help diagnosing. That said, what should be the result if an item with a sticker price of 1.35 is purchased? Perhaps thinking about that and comparing the following will help: IDLE 2.6.6 user_input = 1.35 purchaseAmount = int(user_input) Traceback (most recent call last): File pyshell#1, line 1, in module purchaseAmount = int(user_input) ValueError: invalid literal for int() with base 10: '1.35' user_input = float(1.35) purchaseAmount = int(user_input) purchaseAmount 1 Best, Brian vdB ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help for Python Beginner with extracting and manipulating data from thousands of ASCII files
On 30/09/12 23:07, Cecilia Chavana-Bryant wrote: Hola again Python Tutor! With a friend's help I have the following code to extract reflectance data from an ASCII data file, do a bit of data manipulation to calibrate the data and then write the calibrated file into an out file. snip I have successfully calibrated one ASCII file at a time with this code. However, I have 1,000s of files that I need to calibrate so I would like some help to modify this code so it can: 1. Use one calibration file (Cal_FileP17.txt) on data files created from July to the 18th Sep and a different calibration file (Cal_FileP19.txt) for data files created from the 19th of Sep onwards. 2. Find all the .txt files in a folder called ASCII_files, which is subdivided into 12 different folders and calibrate all these files Number 2 is easier to solve and the os.walk() and glob.glob() functions should provide all the tools you need. Number 1 is more tricky since there is no obvious way to determine the arbitrary start/stop dates you specify. So I'd suggest you need to generalise the requirement to take a start/stop date as well as the calibration file name and the input data file pattern. Use those as input parameters to a function that generates the list of files to process and then calls your existing code (wrapped in a new function) and possibly provide default values for all/some of the parameters. Another option is to add the start/end dates to the calibration file if you have control of that, but personally I'd stick with input parameters... -- 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] Help for Python Beginner with extracting and manipulating data from thousands of ASCII files
On 09/30/2012 06:07 PM, Cecilia Chavana-Bryant wrote: Hola again Python Tutor! With a friend's help I have the following code to extract reflectance data from an ASCII data file, do a bit of data manipulation to calibrate the data and then write the calibrated file into an out file. import numpy # import glob - use if list_of_files is used dataFile = 1SH0109.001.txt #list_of_files = glob.glob('./*.txt') to replace dataFile to search for all text files in ASCII_files folder? First, an important observation. This code has no functions defined in it. Thus it's not reusable. So every time you make a change, you'll be breaking the existing code and then trying to make the new version work. The decision of one file versus many is usually handled by writing a function that deals with one file. Test it with a single file. Then write another function that uses glob to build a list of files, and call the original one in a loop. As you work on it, you should discover that there are a half dozen other functions that you need, rather than one big one. caliFile1 = Cal_File_P17.txt # calibration file to be used on data files created from July to 18 Sep caliFile2 = Cal_File_P19.txt # calibration file to be used on data files created from 19 Sep onwards outFile = Cal_ + dataFile # this will need to change if list_of_files is used fileDate = data[6][16:26] # location of the creation date on the data files Show us the full traceback from the runtime error you get on this line. #extract data from data file fdData = open(dataFile,rt) data = fdData.readlines() fdData.close() #extract data from calibration file fdCal = open(caliFile,rt) Show us the full traceback from the runtime error here, as well. calibration = fdCal.readlines() fdCal.close() #create data table k=0 #just a counter dataNum = numpy.ndarray((2151,2)) #the actual data (the numbers) in the data file begin at line 30 for anItem in data[30:]: theNums = anItem.replace(\r\n,).split(\t) dataNum[k,0] = int(theNums[0]) dataNum[k,1] = float(theNums[1]) k+=1 #advance the counter #create the calibration table k = 0 calNum = numpy.ndarray((2151,2)) for anItem in calibration[5:]: theNums = anItem.replace(\r\n,).split(\t) calNum[k,0] = int(theNums[0]) calNum[k,1] = float(theNums[1]) k+=1 #calibrate the data k=0 calibratedData = numpy.ndarray((2151,2)) for aNum in dataNum: calibratedData[k,0] = aNum[0] #first column is the wavelength calibratedData[k,1] = (aNum[1] * dataNum[k,1]) * 100.0 #second column is the measurement to be calibrated. k+=1 #write the calibrated data fd = open(outFile,wt) Error traceback ? #prior to writing the calibrated contents, write the headers for data files and calibration files fd.writelines(data[0:30]) fd.writelines(calibration[0:5]) for aNum in calibratedData: #Write the data in the file in the following format: # An integer with 3 digits, tab character, Floating point number fd.write(%03d\t%f\n % (aNum[0],aNum[1])) #close the file fd.close() Are the individual files small? By doing readlines() on them, you're assuming you can hold all of both the data file and the calibration file in memory. I have successfully calibrated one ASCII file at a time with this code. Unless I'm missing something, this code does not run. I didn't try it, though, just inspected it quickly. However, I have 1,000s of files that I need to calibrate so I would like some help to modify this code so it can: 1. Use one calibration file (Cal_FileP17.txt) on data files created from July to the 18th Sep and a different calibration file (Cal_FileP19.txt) for data files created from the 19th of Sep onwards. 2. Find all the .txt files in a folder called ASCII_files, which is subdivided into 12 different folders and calibrate all these files I have googled and tried thinking about how to make changes and I've managed to get myself a bit more confused. Thus, I would like some guidance on how to tackle/think about this process and how to get started. Please, I am not asking for someone to do my work and write the code for me, I would like some guidance on how to approach this and get started. Many thanks in advance for your help, Cecilia -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help
On Fri, Sep 21, 2012 at 10:33 AM, Prasad, Ramit ramit.pra...@jpmorgan.com wrote: Ironically, that describes me. So what is the preference for large code samples? Just always include it? What about for the main list? It's tricky. Ideally, you need to take your large code base, and reduce it into a short piece of sample code that is runnable and reproduces your issue. Yes, this can be hard to do, and yes, it can take a lot of time. It should be as short as possible, trimming out all of the extraneous functions and calls. It needs to be short enough that someone interested can actually read it and understand what you're trying to accomplish. It needs to be long enough to actually demonstrate the problem you're having. It's worth the trouble though -- anything longer than a page or two of code is going to get glossed over by many readers -- they just don't have time to read and understand your code, see where you're having a problem and diagnose the issue for you. You're much more likely to get help with a 10 or 20 line sample than with a 100 or 200 line one, much less something that's thousands of lines of code. The people here are volunteers -- the best way to engage them in your problem is to be respectful of their time. Often, that means spending extra time of your own to save their time. In many cases, the act of trimming your code down to that form will actually cause you to find the answer to your own question without even needing to send it. This process is sometimes known as rubber ducking -- http://www.codinghorror.com/blog/2012/03/rubber-duck-problem-solving.html I can't count the number of times that I've had a problem, decided to send it to a mailing list for help, and in the process of fully describing the problem I'm having, come up with the solution without even having to send the email. -- Jerry ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help
I'm having trouble with a small project. Here's what it needs to do:Has variables for window width and window height and creates a window of that size.Has variables which control the number of columns and number of rows.From this, create a checkboard pattern which evenly fills the window. On approximately 10% of the squares (chosen at random) draw an image which is sized to just fit inside a checkboard square (use the smallest dimension).Keep the program open for 3 seconds and then quit.I've attached the code I have so far."Pic" is just a place holder for an actual image.Not sure what to do with the while statements that are empty in the code.Thanks for the help,Brett# Lab 3: Game Board import pygame import time pygame.display.init() WinH = 600 WinW = 800 num_rows = 8 num_cols = 12 screen = pygame.display.set_mode((WinW,WinH)) screen.fill((128,128,128)) markSurf = pygame.image.load(#Pic) color = (0,0,0) cell_width = WinW/num_cols cell_height = WinH/num_rows while #... while #... pygame.draw.rect(screen, color, (cell_width,cell_height), 0) if color == (0,0,0): color = (0,255,0) else: color = (0,0,0) curRow = 0 while curRow #: if curRow %2 = 0: color = (0,0,0) else: color = (0,255,0) curRow +=1 pygame.display.update() time.sleep(3) pygame.display.quit() ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help - My First Program Fails
Hi Steven. Thank you for your answer below. The program now runs, using print(Game Over). I use Python 3..; but the book - python for absolute beginner - that I have is an old (2003) edition. I don't know how this combination may affect my learning, going forward. Could you please suggest how I can something current. Regards. Tayo. My answer to your question appears below: On Sun, Sep 09, 2012 at 03:56:22PM -0700, tayo rotimi wrote: My first exercise: print Game Over does not run! Where have I missed it? The error message is as follows: ?File stdin, line 1 ?? print Game Over ??? ??? ??? ??? ??? ^ ?SyntaxError: invalid syntax Are you using Python 3 instead of Python 2? One of the changes between the 2.x versions and the 3.x versions is that print is no longer a statement, but is now a function. That means you have to write it using round brackets (parentheses for Americans): # version 2.x print Game Over # version 3.x print(Game Over) For simple printing, there's not much advantage either way, but for more advanced printing, the function form is much better. -- Steven___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help - My First Program Fails
On 10/09/12 19:40, tayo rotimi wrote: Hi Steven. Thank you for your answer below. The program now runs, using print(Game Over). I use Python 3..; but the book - python for absolute beginner - that I have is an old (2003) edition. I don't know how this combination may affect my learning, going forward. Could you please suggest how I can something current. You could buy a more current book that covers Python 3 :) E.g. http://www.apress.com/9781430216322 (This is not a recommendation, just the first one I stumbled across.) But honestly, there aren't that many differences between Python 2 and 3. print is the main one. There are a few others, but they are mostly advanced functionality. In my opinion, with a little bit of care and attention to detail, if you are prepared to check the notes in the Fine Manual and if necessarily ask for help here, you can learn Python 3 from a Python 2 book. It won't be *as* convenient, of course, but it will be doable. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help with class in class
I'm in the O'Reilly Python 2 class, so pointers to learning would be better than just answers, please. My brain is a bit slow but needs to go forward. Line 16 calls line 31. Rather, it is supposed to. I'm trying to figure out why I get File ./ch8_project.py, line 31, in change_text_color self.text.tag_configure('highlightline', foreground=fg_color) AttributeError: 'ch8_Project' object has no attribute 'text' If line 31 starts with self. and File ./ch8_project.py, line 31, in change_text_color text.tag_configure('highlightline', foreground=fg_color) NameError: global name 'text' is not defined If Line 31 does not start with self.. I understand the second problem but not the first. What am I missing? Thanks! Leam -- Mind on a Mission http://leamhall.blogspot.com/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with class in class
Of course, showing the code might help... http://bpaste.net/show/44593/ Thanks! Leam On Sun, Sep 9, 2012 at 10:42 AM, leam hall leamh...@gmail.com wrote: I'm in the O'Reilly Python 2 class, so pointers to learning would be better than just answers, please. My brain is a bit slow but needs to go forward. Line 16 calls line 31. Rather, it is supposed to. I'm trying to figure out why I get File ./ch8_project.py, line 31, in change_text_color self.text.tag_configure('highlightline', foreground=fg_color) AttributeError: 'ch8_Project' object has no attribute 'text' If line 31 starts with self. and File ./ch8_project.py, line 31, in change_text_color text.tag_configure('highlightline', foreground=fg_color) NameError: global name 'text' is not defined If Line 31 does not start with self.. I understand the second problem but not the first. What am I missing? Thanks! Leam -- Mind on a Mission http://leamhall.blogspot.com/ -- Mind on a Mission http://leamhall.blogspot.com/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with class in class
On Sun, Sep 9, 2012 at 5:43 PM, leam hall leamh...@gmail.com wrote: Of course, showing the code might help... http://bpaste.net/show/44593/ Thanks! Leam On Sun, Sep 9, 2012 at 10:42 AM, leam hall leamh...@gmail.com wrote: I'm in the O'Reilly Python 2 class, so pointers to learning would be better than just answers, please. My brain is a bit slow but needs to go forward. Line 16 calls line 31. Rather, it is supposed to. I'm trying to figure out why I get File ./ch8_project.py, line 31, in change_text_color self.text.tag_configure('highlightline', foreground=fg_color) AttributeError: 'ch8_Project' object has no attribute 'text' If line 31 starts with self. and File ./ch8_project.py, line 31, in change_text_color text.tag_configure('highlightline', foreground=fg_color) NameError: global name 'text' is not defined If Line 31 does not start with self.. I understand the second problem but not the first. What am I missing? Thanks! Leam -- Mind on a Mission -- Mind on a Mission ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Please do not top post. --- And the problem is: add_text_widget() defines a local (function-wide) `text` object rather than a class-wide one. Just prepend the `text` object with `self.` and it will be solved. Also, if you are planning to use more than one of those, you will need to do it in another way. Bonus question: why py3k? -- Kwpolska http://kwpolska.tk stop html mail | always bottom-post www.asciiribbon.org | www.netmeister.org/news/learn2quote.html GPG KEY: 5EAAEA16 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with class in class
leam hall wrote: I'm in the O'Reilly Python 2 class, so pointers to learning would be better than just answers, please. My brain is a bit slow but needs to go forward. Line 16 calls line 31. Rather, it is supposed to. I'm trying to figure out why I get File ./ch8_project.py, line 31, in change_text_color self.text.tag_configure('highlightline', foreground=fg_color) AttributeError: 'ch8_Project' object has no attribute 'text' If line 31 starts with self. and File ./ch8_project.py, line 31, in change_text_color text.tag_configure('highlightline', foreground=fg_color) NameError: global name 'text' is not defined If Line 31 does not start with self.. I understand the second problem but not the first. What am I missing? When inside a method you assign to self.whatever = ... you are setting an attribute of the class. If you assign to a name whatever = ... you are setting a local variable. So #!/usr/bin/env python3 from tkinter import * SIDE = W+E ALL = N+E+W+S class ch8_Project(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.file_open(./fred) fg_color = Red self.pack() self.add_text_widget( fg_color, self.out_text) self.green = Button(root, text=Green, command=self.change_text_color(green)) self.green.pack(side=TOP) def add_text_widget(self, fg_color, out_text): text = Text(root) in the above line you are making a local variable which will be forgotten when the method terminates. Change the line to self.text = Text(root) do the same for the following lines, and text.insert(INSERT, out_text) text.tag_configure('highlightline', foreground='red') text.tag_add('highlightline', '1.0', 'end') text.pack() def file_open(self, file_name): file = open(file_name, r) self.out_text = file.read() def change_text_color(self, fg_color): self.text.tag_configure('highlightline', foreground=fg_color) the above will no longer complain about a missing attribute. root = Tk() project = ch8_Project(master=root) project.mainloop() Another problem that caught my attention: self.green = Button(root, text=Green, command=self.change_text_color(green)) The command argument is supposed to be a function; you are instead assigning the result of a method call (which is None in this case, but as a side effect will set the color to green immediately. The simplest fix is to define a helper function that takes no arguments ... def change_to_green(): self.change_text_color(green) self.green = Button(root, text=Green, command=change_to_green) ... If you already know about lambda you can try to rewrite this using that. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with class in class
On Sun, Sep 9, 2012 at 12:12 PM, Peter Otten __pete...@web.de wrote: the above will no longer complain about a missing attribute. root = Tk() project = ch8_Project(master=root) project.mainloop() Another problem that caught my attention: self.green = Button(root, text=Green, command=self.change_text_color(green)) The command argument is supposed to be a function; you are instead assigning the result of a method call (which is None in this case, but as a side effect will set the color to green immediately. The simplest fix is to define a helper function that takes no arguments ... def change_to_green(): self.change_text_color(green) self.green = Button(root, text=Green, command=change_to_green) ... If you already know about lambda you can try to rewrite this using that. Peter, thank you for helping me understand the scope issue I was missing! I knew it was something like that but forget that omitting this. meant the variables were limited in scope to that method. I have seen lamba but do not understand it. The project requires four buttons, each one turns the same text a different color. The class is also Python 3 based. :) Leam -- Mind on a Mission http://leamhall.blogspot.com/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with class in class
self.blue = Button(root, text=Blue, command=self.change_text_color(blue)) self.blue.pack(side=LEFT) self.green = Button(root, text=Green, command=self.change_text_color(green)) self.green.pack(side=LEFT) To follow up, I've added a second button. Of course, it doesn't work, the text comes out as the color of the last button. It is running the commands in the Button line without the buttons being clicked. More research... -- Mind on a Mission http://leamhall.blogspot.com/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with class in class
On 09/09/2012 04:56 PM, leam hall wrote: self.blue = Button(root, text=Blue, command=self.change_text_color(blue)) self.blue.pack(side=LEFT) self.green = Button(root, text=Green, command=self.change_text_color(green)) self.green.pack(side=LEFT) To follow up, I've added a second button. Of course, it doesn't work, the text comes out as the color of the last button. It is running the commands in the Button line without the buttons being clicked. More research... Please reread Peter's message, starting with Another problem... He identifies the problem, and mentions one way to fix it. In your response, you mentioned to lambda, so you must have seen it. In particular, the Button() function takes a function object as its command= parameter. You call the function yourself, and pass the return value, which of course is not what's wanted. You don't want the function called till someone presses the button. So you want something equivalent to = Button(root, text=Blue, command=change_to_green) Notice that there are NO parentheses on that change_to_green. You want the function object, you do NOT want to call the function. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help - My First Program Fails
My first exercise: print Game Over does not run! Where have I missed it? The error message is as follows: File stdin, line 1 print Game Over ^ SyntaxError: invalid syntax I am still surprised at this error. I 'll appreciate your help. Regards. Tayo From: tutor-requ...@python.org tutor-requ...@python.org To: tutor@python.org Sent: Sunday, September 9, 2012 10:14 PM Subject: Tutor Digest, Vol 103, Issue 40 Send Tutor mailing list submissions to tutor@python.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.python.org/mailman/listinfo/tutor or, via email, send a message with subject or body 'help' to tutor-requ...@python.org You can reach the person managing the list at tutor-ow...@python.org When replying, please edit your Subject line so it is more specific than Re: Contents of Tutor digest... Today's Topics: 1. Re: Help with class in class (leam hall) 2. Re: I Need Help - further details now provided. (Matthew Ngaha) 3. web frameworks (Matthew Ngaha) 4. Re: web frameworks (Steven D'Aprano) 5. Re: Help with class in class (leam hall) 6. Re: web frameworks (Matthew Ngaha) 7. Re: Help with class in class (Dave Angel) -- Message: 1 Date: Sun, 9 Sep 2012 14:12:48 -0500 From: leam hall leamh...@gmail.com To: tutor tutor@python.org Subject: Re: [Tutor] Help with class in class Message-ID: cacv9p5rm28nvdnhzyfd4pmdeqjmhzsjzjqhidde5mcm70o7...@mail.gmail.com Content-Type: text/plain; charset=utf-8 On Sun, Sep 9, 2012 at 12:12 PM, Peter Otten __pete...@web.de wrote: the above will no longer complain about a missing attribute. root = Tk() project = ch8_Project(master=root) project.mainloop() Another problem that caught my attention: self.green = Button(root, text=Green, command=self.change_text_color(green)) The command argument is supposed to be a function; you are instead assigning the result of a method call (which is None in this case, but as a side effect will set the color to green immediately. The simplest fix is to define a helper function that takes no arguments ... def change_to_green(): self.change_text_color(green) self.green = Button(root, text=Green, command=change_to_green) ... If you already know about lambda you can try to rewrite this using that. Peter, thank you for helping me understand the scope issue I was missing! I knew it was something like that but forget that omitting this. meant the variables were limited in scope to that method. I have seen lamba but do not understand it. The project requires four buttons, each one turns the same text a different color. The class is also Python 3 based. :) Leam -- Mind on a Mission http://leamhall.blogspot.com/ -- next part -- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tutor/attachments/20120909/94464518/attachment-0001.html -- Message: 2 Date: Sun, 9 Sep 2012 20:20:19 +0100 From: Matthew Ngaha chigga...@gmail.com To: tutor@python.org Subject: Re: [Tutor] I Need Help - further details now provided. Message-ID: CACzNyA0WsuSr3jUXJ46hNL1TtbKfCYK=bqtc+e-y_trp2s8...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 SORRY i wrote to you not the mailing list:( im a beginner myself, and those instructions seem very complicated for me. But i did install Python and everything included with no problem. You need at least Python 3.1 for this book we have. its what the author recommended. version 2.7 as you have shown in the link is too old as it has different syntax. Try downloading Python from the link i included, you will have no trouble installing IDLE with this link. -- Message: 3 Date: Sun, 9 Sep 2012 20:41:24 +0100 From: Matthew Ngaha chigga...@gmail.com To: tutor@python.org Subject: [Tutor] web frameworks Message-ID: CACzNyA1t=p5gprfdav-mejqua-qyb-lqvcyg-bvyqqdxkpb...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 Hi all, i had a recent post about learning about guis and web applications. i decided to try guis 1st, but i also decided that maybe a very very very simple web framework would not be too much work for me to study once in while. I decided on Flask because i read it's the simpliest framework out of all the others i've researched, only to find out it's not supported on Python 3:(.. i wondered if someone with experience can tell me, in their opinion a framework with a similar learning curve to Flask that a beginner can easily understand and is supported on Python 3. i thought cherrypy, but was told it's not nearly as simple as Flask, and since my main focus is learning GUIs, a simple web framework will be ideal only to understand how they work. i understand Javascript only a little, but html and css a bit better etc.. also
Re: [Tutor] Help - My First Program Fails
Please, please, PLEASE do not reply to a digest without deleting the irrelevant text from your email! We don't need to read HUNDREDS of lines of text we've already seen before. When you want to start a *new* question, ALWAYS start a fresh, blank email, set the To address to tutor@python.org, and DO NOT reply to a digest. Thank you. My answer to your question appears below: On Sun, Sep 09, 2012 at 03:56:22PM -0700, tayo rotimi wrote: My first exercise: print Game Over does not run! Where have I missed it? The error message is as follows: File stdin, line 1 print Game Over ^ SyntaxError: invalid syntax Are you using Python 3 instead of Python 2? One of the changes between the 2.x versions and the 3.x versions is that print is no longer a statement, but is now a function. That means you have to write it using round brackets (parentheses for Americans): # version 2.x print Game Over # version 3.x print(Game Over) For simple printing, there's not much advantage either way, but for more advanced printing, the function form is much better. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help
Hey, I am writing this to you because I want to know could you help. My school is doing enterprise and I want to enter. I really want to make a program that will clean up your desktop E.G put files you haven't used for a while into a folder and delete your trash they are just a few ideas. I am trying to learn programming but I live in Ireland and where I live they is not much access to courses so I have to wait till college to learn programming. I have tried to learn some of python through on-line tutorials but find it hard So what I am asking is could you help me make a program if not I understand as I can imagine ye are very busy people. Thanks for reading this. Ian Lawlor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help
Ok, I am somewhat new to python, and I am making a text-based RPG. I get a weird error with this code: #A Python text-RPG #A Jak Production #APOC global ammo global health global lives global exp global food ammo=55 health = 100 lives=10 exp = 0 food = 30 def part1(): print 50 Days After The Outbreak:You are standing outside of the Empire State Building. print Vines, plants, dirt, and grime cover its once-regal surfaces. Huh. print I guess if 80% of the world is dead, more people are concerned about survival than sightseeing.God. print Generally,us survivors tend to band together. Mostly it is for good. Not the bandits. print Bandit:'Hey you! What you got in that bag? print I recognized this Bandit as Sam Cabelo. He was the janitor at my office building. Not the nicest fellow. answer = raw_input(Type 'show' or 'run away' then hit the 'Enter' button.) if answer == SHOW or answer == Show or answer == show: print Ahhh. Nice .45 you got there. And some food.Hand it over.(He says this like a threat, reinforced by that revolver in his hand answer2 = raw_input(Type either Hand it over or flee) if answer2 == HAND IT OVER or answer2 == Hand it over or answer2 == hand it over: print Bandit: Good Job.. Go on now ammo=ammo-15 food=food-10 return answer3 if answer2 == FLEE or answer2 == Flee or answer2 == flee: print He shot you lives=lives-1 else: print TYPE SOMETHING CORRECTLY return part1 elif answer == run away or Run Away or RUN AWAY: print He shot you... hee hee hee print When the input comes up again, type a differet answer else: print You didn't type Show or run away. part1() part1() Here is my error, if it helps Traceback (most recent call last): File C:\Users\Jack\Desktop\game2.py, line 45, in module part1() File C:\Users\Jack\Desktop\game2.py, line 28, in part1 ammo=ammo-15 UnboundLocalError: local variable 'ammo' referenced before assignment Thanks, Jack Little ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help
On 09/03/2012 07:39 AM, Jack Little wrote: Ok, I am somewhat new to python, and I am making a text-based RPG. I get a weird error with this code: #A Python text-RPG #A Jak Production #APOC global ammo global health global lives global exp global food ammo=55 health = 100 lives=10 exp = 0 food = 30 def part1(): print 50 Days After The Outbreak:You are standing outside of the Empire State Building. print Vines, plants, dirt, and grime cover its once-regal surfaces. Huh. print I guess if 80% of the world is dead, more people are concerned about survival than sightseeing.God. print Generally,us survivors tend to band together. Mostly it is for good. Not the bandits. print Bandit:'Hey you! What you got in that bag? print I recognized this Bandit as Sam Cabelo. He was the janitor at my office building. Not the nicest fellow. answer = raw_input(Type 'show' or 'run away' then hit the 'Enter' button.) if answer == SHOW or answer == Show or answer == show: print Ahhh. Nice .45 you got there. And some food.Hand it over.(He says this like a threat, reinforced by that revolver in his hand answer2 = raw_input(Type either Hand it over or flee) if answer2 == HAND IT OVER or answer2 == Hand it over or answer2 == hand it over: print Bandit: Good Job.. Go on now ammo=ammo-15 I'll take a stab at it. You are using attempting to modify a global variable within a procedure. Procedure variables are separate from global variables. Global variables must be passed into a procedure using something on the order of 'part1(ammo)', and then returned back from the procedure with a 'return value' Ray ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help
On 09/03/2012 10:39 AM, Jack Little wrote: Ok, I am somewhat new to python, and I am making a text-based RPG. I get a weird error with this code: #A Python text-RPG #A Jak Production #APOC global ammo global health global lives global exp global food ammo=55 health = 100 lives=10 exp = 0 food = 30 def part1(): print 50 Days After The Outbreak:You are standing outside of the Empire State Building. print Vines, plants, dirt, and grime cover its once-regal surfaces. Huh. print I guess if 80% of the world is dead, more people are concerned about survival than sightseeing.God. print Generally,us survivors tend to band together. Mostly it is for good. Not the bandits. print Bandit:'Hey you! What you got in that bag? print I recognized this Bandit as Sam Cabelo. He was the janitor at my office building. Not the nicest fellow. answer = raw_input(Type 'show' or 'run away' then hit the 'Enter' button.) if answer == SHOW or answer == Show or answer == show: print Ahhh. Nice .45 you got there. And some food.Hand it over.(He says this like a threat, reinforced by that revolver in his hand answer2 = raw_input(Type either Hand it over or flee) if answer2 == HAND IT OVER or answer2 == Hand it over or answer2 == hand it over: print Bandit: Good Job.. Go on now ammo=ammo-15 food=food-10 return answer3 if answer2 == FLEE or answer2 == Flee or answer2 == flee: print He shot you lives=lives-1 else: print TYPE SOMETHING CORRECTLY return part1 elif answer == run away or Run Away or RUN AWAY: print He shot you... hee hee hee print When the input comes up again, type a differet answer else: print You didn't type Show or run away. part1() part1() Here is my error, if it helps Traceback (most recent call last): File C:\Users\Jack\Desktop\game2.py, line 45, in module part1() File C:\Users\Jack\Desktop\game2.py, line 28, in part1 ammo=ammo-15 UnboundLocalError: local variable 'ammo' referenced before assignment Thanks, Jack Little Your global declarations are all at top-level scope, where they are meaningless. All variables defined there are global. What you want for ammo is a global declaration inside the function. By convention, you declare any globals at the top of the function, right after the def and the doc-string. You'll also need global declarations for food and lives, and perhaps others I didn't notice. Other things I notice: You omitted the parentheses in one reference to part1. So it doesn't get called there. You try to use those part1() calls as some form of looping construct. Instead you should use a while loop or similar. That also will avoid the problem you've got now where if a person types nonsense to the second question, he ends up being asked the first question again. Use lower() method on strings to avoid needing multiple comparisons: if answer2.lower() == flee: -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] help me decide
hey guys i just like to thank everyone for their input. Its really helped me in deciding a lot of things. also @ Alan i think? as ive started writing this mail it won;t let me look up previous senders but thanks for your input. Also your field of work sounds very interesting indeed. I can't dare to imagine the amount of hard work that got you there.:) i only hope my dedication can take me half as far:) Best wishes to everyone:x ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help
On 06/09/12 09:35, Ray Jones wrote: #A Python text-RPG #A Jak Production #APOC global ammo You use global inside a function not outside. All variables declared at the module level are global by definition. ammo=55 This sets the global ammo value def part1(): if answer == SHOW or answer == Show or answer == show: answer2 = raw_input(Type either Hand it over or flee) if answer2 == HAND IT OVER or answer2 == Hand it over or answer2 == hand it over: print Bandit: Good Job.. Go on now ammo=ammo-15 Here you try to create a local variable in the function butuse that variable in its definition. What you really wanted was to use the global ammo. To do that you need to tell the function that any reference to ammo will use the global value, like this def part1(): global ammo at the top of the function. Ray added: I'll take a stab at it. You are using attempting to modify a global variable within a procedure. Procedure variables are separate from global variables. Global variables must be passed into a procedure using something on the order of 'part1(ammo)', and then returned back from the procedure with a 'return value' That's not strictly true, as explained above. However, it is generally considered good programming practice not to rely on globals but to pass values in as parameters as you do in your example here. So good practice says part1() should be defined as: def part1(theAmmo, theFood, theLives): # as is code... Notice I changed the names to distinguish them from the global variables. and you call it using the global variables as: part1(ammo,food,lives) The other thing to note is that at one point you use return part1 That returns the function itself which is almost certainly not what you want. You also return answer3 which doesn't seem to be defined anywhere. Returning lots of different values from the same function will make it very hard to use. You should think about breaking this down into the code that gets the user responses and separate code that returns the required values, one value per function. And finally at the end you call part() from within part(), that's a technique called recursion and can get you into all sorts of problems if you don't know what you are doing with it. What you really want is a loop that repeats the input code until you get valid values. A while loop is probably best in this case. -- 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] Help
Hi Ian, On 4 September 2012 20:36, Ian o donovan ianodonova...@gmail.com wrote: Hey, I am writing this to you because I want to know could you help. My school is doing enterprise and I want to enter. What do you mean your school is doing enterprise? Is it some competition or something? I really want to make a program that will clean up your desktop E.G put files you haven't used for a while into a folder and delete your trash they are just a few ideas. I am trying to learn programming but I live in Ireland and where I live they is not much access to courses so I have to wait till college to learn programming. I have tried to learn some of python through on-line tutorials but find it hard So what I am asking is could you help me make a program if not I understand as I can imagine ye are very busy people. You're at the right place to ask beginner Python questions. Feel free to try stuff and ask questions when you run into problems. Be sure to post complete error messages, what you've tried, what happened and what you expected to happen instead. As for courses, you may want to look into the following free educational offerings where you can learn basic programming in a structured manner: https://www.coursera.org/course/interactivepython http://www.udacity.com/overview/Course/cs101/CourseRev/apr2012 http://www.khanacademy.org/science/computer-science https://www.edx.org/courses/HarvardX/CS50x/2012/about Be sure to browse around the sites, most of the sites have multiple courses available. HTH Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help
On 03/09/2012 15:39, Jack Little wrote: Ok, I am somewhat new to python, and I am making a text-based RPG. I get a weird error with this code: [snip] Thanks, Jack Little Further to the sound advice you've already been given a rather more informative subject line would have been helpful :) My apologies if someone has already said this and I've missed it. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] help me decide
Hi Alan thanks so much for your helpful answers. probably wxPython or GTk But if you want to get serious about GUIs I'd probably suggest wxPython instead - it ultimately is more powerful and complete and if you are only just starting will be easy to learn whereas learning Tkinter and converting is more difficult (IMHO). PyQt is powerful too but there are several limitations in its licensing model that leave me slightly wary. Gtk is another option. Both of these were originally made popular in the Linux community but both are available cross platform now. (as are Tkinter and wxPython) After your response ive decided GUI programming is defintely better for me at this stage. I read Pyside is a replica of pyqt, same makers qt but it covers all the licensing that PyQt doesnt, and if you learn 1 the other is almost exactly the same. Would this be a good enough reason to give it and pyqt a try? how does it compare to wxPython? also please could you tell me why you suggest wxPython over GTK? what are the factors you looked at, is it better for beginners to start out with a simpler toolkit and decide later on if its enough for them? would you say out of the GUIs we have mentioned, apart from Tkinter, that wxPython is the easiet to pick up yet a lot more complete than Tkinter? I'm not a big fan of user interface programming in any shape. I started my career writing embedded software where the UI was a switch and some LEDs. So i am more interested in the internals of a program than in its outer appearance, but from necessity I've done a little bit of GUI work and even less web work. this has interested me. is embedded programming a different field to the type of programming in Python? it sounds like thats more lower level prgroamming better suited to a language like C? is your work today still related to this area? somewhere down the learn, after i have mastered Python i'd definately like to learn about internals of a program, even though the thought of that really scares me:) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] help me decide
From: Matthew Ngaha [snip] i feel confident using Python now but im still not sure which direction i want to go in. I would at some point like to learn how to use GUIs and a web Framework(Django). But i don't know which of the 2 to start out with. a) IF you happen to have used both, which one fills you with joy and is more fun for you to program with, GUI programming, or web related / Framework programming? b) which was easier and less complex for you to learn? or should i say had a lower learning curve? i ask this because the sooner i get an understanding of one, i can maybe give the other one a go. But if it's too hard i usually give 100% to it and never try learning anything else until it computes. [snip] Before i try to learn either, GUIs or a web Framework, i was looking into maybe getting a deeper understanding of OOP. my tutorial only covered it briefly. f) would this be a good idea tackling OOP next before the other 2, or is this a skill you master with more programming experience? ok my last question is not so important:) im just curious as i grow more fond of programming. well i keep reading Python is an all-purpose general programming language(web frameworks, desktop apps, science/maths etc..). I notice Java has similar features so should also be considered an all-purpose general programming language. my question is: g) not a comparison in 1 specific area, but which language is better or more suited to all around all-purpose quality. thanks guys I would second the wxPython framework as a popular and fully featured framework; being popular means it will likely be easier to get help on it. I was *not* a fan of GUI in Java using Swing. Stick with Python, but this list is probably biased. :) The real question is what do you want to *do* with it? The purpose or intent probably matters more than which you pick. If you are learning for the sake of learning I would probably point you in the direction of web frameworks. In my personal opinion there is more opportunity there. Not to mention that the basics you learn in web frameworks will help you design web sites in other languages as well. Whereas desktop applications will probably be a lot more specific to the framework/language and project. That is just my personal observations. Others (including you) may disagree. Ramit ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] help me decide
On 05/09/12 11:04, Matthew Ngaha wrote: also please could you tell me why you suggest wxPython over GTK? Support, there are probably more beginner friendly resources for wxPython than for GTk, although that is changing. that wxPython is the easiet to pick up yet a lot more complete than Tkinter? I can't really comment since Tkinter and wxPython are the only two i've really used. I did a PyQt tutorial a long time back and have never used GTk at all so can't really comment on them. this has interested me. is embedded programming a different field to the type of programming in Python? Yes, it is usually done using assembler and C or C++. Some embedded work nowadays is done in Java - a reflection of how cheap memory has become! is your work today still related to this area? Not really, my company (a big telecomms business) got out of making bespoke hardware and now buys in standard commercial kit. My core job these days is as an Enterprise Architect and I do almost no programming now. I determine what IT systems are needed, the interfaces between them and review the high level systems designs. I act as a bridge between the business folks and the IT tech heads... I 'own' around 250 systems and oversee the technical work of around 1000 developers, with about 20 projects running at any one time. Python programming has become more of a hobby and personal productivity tool nowadays. It keeps me sane and connected! :-) -- 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] help me decide
On 05-Sep-12 10:40, Alan Gauld wrote: On 05/09/12 11:04, Matthew Ngaha wrote: also please could you tell me why you suggest wxPython over GTK? Support, there are probably more beginner friendly resources for wxPython than for GTk, although that is changing. Yeah, and wxPython is a large, comprehensive package that should handle all of your GUI needs and then some. I wrote one tool using wxPython and was quite happy with the results, and pleasantly surprised at the performance of widget updates and refreshes it achieved, even for the bits in pure Python. that wxPython is the easiet to pick up yet a lot more complete than Tkinter? Not sure about that. I started Tk programming back (way back) in my Tcl/Tk phase years ago, so I'm really used to Tk and that may bias me, but I'd say Tkinter is a lot easier to learn than wxPython, partly because it's smaller with fewer moving parts to tweak. And yet, Tkinter is complete enough to be quite satisfactory for a lot of applications. Even after using wx, I've gone back to Tkinter when it sufficed for my applications, since it's a little easier to use and is a lot easier to distribute, coming for free with Python and all that. this has interested me. is embedded programming a different field to the type of programming in Python? Yes, it is usually done using assembler and C or C++. Some embedded work nowadays is done in Java - a reflection of how cheap memory has become! Right. Although Java here doesn't necessarily mean the JVM is running on the embedded machine; it could be Java source code compiled down to something a compact runtime can execute. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] help me decide
No matter what the kit used for GUI, make sure it's well documented, and has plenty of tuts/docs. I used tkinter, and wxpython, and like the widget set/cross OS usages in wxpython better. However, with more experience, now I'm moving toward the Blender Game Engine to give more feel, and a 3-d pop to my apps through it's Python API. So, consider that over time your preferences will change in relation to your knowledge, and the wisdom that comes with the application of this knowledge...experience. Also, don't get hung up on just python. Always take a beginner's guide or two with a well referenced language(all the way down to assembly/machine language) for familiarity. -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] help me decide
On Tue, 4 Sep 2012, Matthew Ngaha wrote: a) IF you happen to have used both, which one fills you with joy and is more fun for you to program with, GUI programming, or web related / Framework programming? Honestly - both. It's really a highly subjective question and depends what you want to do (although with modern browsers like Google Chrome and Firefox the line is becoming more and more blurry). If you want to provide an application that requires no interaction with the outside world, a GUI is probably a better fit and has the advantage that you'll probably only be using one language - in this case, Python ;) But if you begin doing web programming then you'll start to learn about HTML, JavaScript, and CSS (all valuable technologies and look like they'll be here to stay!) b) which was easier and less complex for you to learn? or should i say had a lower learning curve? i ask this because the sooner i get an understanding of one, i can maybe give the other one a go. But if it's too hard i usually give 100% to it and never try learning anything else until it computes. Honestly, I picked up learning HTML before I learned to actually program. That's what got me interested, was being able to make small changes in the text and see large changes happen in my page. I would say as far as complexity goes, learning basic GUI programming has less pieces. But again, both directions are perfectly valid and valuable things to learn. my tutorial had a small section on tkinter. I have now looked for some tutorials and noticed Python tutorials on both tkinter and Tk. As i understand they are not the same thing but tkinter is like the interface of Tk? my question is: I'm sure someone has addressed this already, but Tkinter is the Python bindings for Tk/Tcl. It allows you to write Python code to do Tk things. c) which tutorial would be better to study, Tkinter or Tk? and what exactly is the difference? why do they have separate tutorials? You would definitely want to focus on Tkinter - and there are quite a few good tutorials, including the effbot tutorial. That's a reference I turn to almost any time I'm doing Tkinter. i looked at some pyQT articles, but its coding looks less organised than Tkinter. I wouldn't say it's less organized, but there's a *lot* more to Qt than Tkinter. d) is this true? is Tkinter a lot more straight forward and Python friendly? One thing I noticed about Qt is that you'll be using the Q key a lot. So your left pinky (assuming two hands and a Qwerty keyboard) will get a massive workout. It was super awkward for me while I was learning it. e) Does pyQT have grids (rows and columns) to place your widgets on like Tkinter, or do you have to use x and y axis to position widgets etc..? You can do both... In terms of GUI frameworks, I rank them in this order from least- to most-complex: 1. Tkinter 2. wxPython 3. PyGTK+ 4. PyQt Tkinter is kinda the raw materials. You get a few widgets (though that's really grown in the past few years with ttk and tix), and some building blocks. wxPython gives you some tools to interface with the native UI - so if you set it up right, the same Python application will look like a real Windows app, a real Gnome(GTK) app, or what have you. PyGTK seems to me like it gives you a bit more than wx. Again, this is largely subjective. I used to do quite a bit with PyGTK. The normal GTK documentation maps quite well, though it can be a little difficult to figure out why something is doing what it's doing. PyQt... well that's everything and the kitchen sink. I mean seriously - there's a timer widget built in! It's quite the powerhouse, but ultimately I didn't like using my left pinky to hit the Q key so much. Before i try to learn either, GUIs or a web Framework, i was looking into maybe getting a deeper understanding of OOP. my tutorial only covered it briefly. f) would this be a good idea tackling OOP next before the other 2, or is this a skill you master with more programming experience? I personally would consider OOP fundamentals essential to learning GUI programming with anything besides Tkinter. It's pretty easy to write procedural-ish Tkinter code. ok my last question is not so important:) im just curious as i grow more fond of programming. well i keep reading Python is an all-purpose general programming language(web frameworks, desktop apps, science/maths etc..). I notice Java has similar features so should also be considered an all-purpose general programming language. my question is: g) not a comparison in 1 specific area, but which language is better or more suited to all around all-purpose quality. I'm sure the other folks have mentioned that Java is an extremely verbose language that (at least to me) is entirely too noisy. I did *not* enjoy the two semesters in college that I had to use it. The term Martin Fowler uses to describe it is a guiding language. That means that Java has
[Tutor] help me decide
hey guys as i program more, i think of silly questions i would like answers to. if anyone doesnt mind entertaining my question, please do answer:) I have just about finished my beginner tutorial, just a few exercises left. i feel confident using Python now but im still not sure which direction i want to go in. I would at some point like to learn how to use GUIs and a web Framework(Django). But i don't know which of the 2 to start out with. a) IF you happen to have used both, which one fills you with joy and is more fun for you to program with, GUI programming, or web related / Framework programming? b) which was easier and less complex for you to learn? or should i say had a lower learning curve? i ask this because the sooner i get an understanding of one, i can maybe give the other one a go. But if it's too hard i usually give 100% to it and never try learning anything else until it computes. my tutorial had a small section on tkinter. I have now looked for some tutorials and noticed Python tutorials on both tkinter and Tk. As i understand they are not the same thing but tkinter is like the interface of Tk? my question is: c) which tutorial would be better to study, Tkinter or Tk? and what exactly is the difference? why do they have separate tutorials? i looked at some pyQT articles, but its coding looks less organised than Tkinter. d) is this true? is Tkinter a lot more straight forward and Python friendly? e) Does pyQT have grids (rows and columns) to place your widgets on like Tkinter, or do you have to use x and y axis to position widgets etc..? Before i try to learn either, GUIs or a web Framework, i was looking into maybe getting a deeper understanding of OOP. my tutorial only covered it briefly. f) would this be a good idea tackling OOP next before the other 2, or is this a skill you master with more programming experience? ok my last question is not so important:) im just curious as i grow more fond of programming. well i keep reading Python is an all-purpose general programming language(web frameworks, desktop apps, science/maths etc..). I notice Java has similar features so should also be considered an all-purpose general programming language. my question is: g) not a comparison in 1 specific area, but which language is better or more suited to all around all-purpose quality. thanks guys ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] help me decide
Matthew, Program what is fun for you. I prefer PHP for web work but I'm learning Python for my day job. Python provides a wider range of abilities but PHP is more fun for me. If Python GUIs are fun, then do that. The more you enjoy the topic the more reason you will have to learn more and more. I doubt you will exhaust Python's capabilities any time soon. Python or Java? For me it's Python. The only real Java advantage might be Android programming. Leam -- Mind on a Mission http://leamhall.blogspot.com/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] help me decide
sorry wrong i didnt send mail right. hey i didnt explain it properly, i wasn't asking what language to use or learn. I am only going to be using Python. I meant whic area to study on 1st, GUI programing e.g Tkinter or Programming with a web framwork e.g Django. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] help me decide
hey you didnt read my question:( i dont enjoy either because i have no experience with them. so im asking questions about peoples personal experiences with the 2 areas which can give me further information to research on. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help : File formatting
Hi, I am beginner to python and doing coding on UNIX platforms(AIX,Linux,HP,Solaris) I want to take the list of files present in packages. On AIX we get the files list present in packges using command lslpp -f pkgname. Now i want to format output of above command such that only list of files with absolute paths to be taken out and put into separate list/dictionary. I am considering here the remote connectivity of hosts. Will you please guide me to get the solution for this ? -Rahul Shelke ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help : File formatting
On 23/08/12 07:12, rahool shelke wrote: I want to take the list of files present in packages. On AIX we get the files list present in packges using command lslpp -f pkgname. Can you provide a short example of the output format from lslpp? Now i want to format output of above command such that only list of files with absolute paths to be taken out and put into separate list/dictionary. Can you define precise rules for determining an absolute path? I am considering here the remote connectivity of hosts. I'm not sure what you mean by that, can you elaborate? What are you considering? How to connect to them? How to specify them in the filenames? Will you please guide me to get the solution for this ? The easiest way is for you to try what you think should work and post it along with what happened and your questions. That tells us your coding level and expectations. Please include the python version and the full text of any error messages not just a summary. -- 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
[Tutor] Hello Python Tutor - help please!
Hi, Cecilia: I came across your posts when catching up with my tutor-request digest emails. I did not see the Udacity site mentioned--if it was, my apologies for the repetition. Udacity.com, a free online education service, offers a number of high-quality courses. They include interactive quizzes using code sandboxes. The courses are 7 weeks long with online office hours and forums. If you do not want to wait for the next start date, you can take the courses online without getting instructor responses to students' posts. Free Interactive Computer Courses (interaction via online quizzes using code sandboxes): http://www.udacity.com/ Intro to Computer Science Python -- Beginner -- Project create functional search engine http://www.udacity.com/view#Course/cs101/CourseRev/apr2012/Unit/671001/Nugget/675002 Programming Languages Python, JavaScript -- Intermediate -- Project: Build a Functional Web Browser http://www.udacity.com/view#Course/cs262/CourseRev/apr2012/Unit/3001/Nugget/5001 Web Application Engineering Python -- Intermediate -- Project: Build a Functional Blog http://www.udacity.com/view#Course/cs253/CourseRev/apr2012/Unit/4001/Nugget/5002 Other courses available. Best regards, Ron Painter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Hello Python Tutor - help please!
Dear all, I am just returning to my doctoral studies after a 7-month medical leave and desperately trying to catch up for lost time. I am COMPLETELY new to programming, well, I did try learning C for 3 weeks 3 yrs ago (with very little success) but had to stop and then spent 2 years in the Amazon climbing trees (lots more enjoyable than learning to programme!) and collecting loads of field data that I now need to post-process and analyse. By the way, the 3 weeks I spent trying to learn C really ended up being spent trying to get to grips with using a terminal for the first time in my life. Since getting back to work, I was advised to try learning Python instead of C as it is a much easier first language to learn. I have been trying, but again, to not great success. I started following A Primer on Scientific programming with Python but I kept getting lost and stuck, specially on the exercises. I have also been advised that I should not try to learn programming by following guides but by trying to write the programmes I need to analyse my data. Although I can understand the logic behind this last bit of advise (it gives context and direction to the learning process) I have also gotten stuck trying this approach as I do not know how to programme!. Thus, I was hoping that some of you can remember how you got started and point me towards any really good interactive learning guides/materials and/or have a good learning strategy for a complete beginner. I have searched the web and was overwhelmed by choice of tutorials and guides. I have skimmed through a couple of tutorials but then fail to see how all that relates to my own work and I get stuck with what seems like basic important concepts so I don't progress. I then think I should try to make some progress with my own data analysing and go back to trying to learn to write a programme for my specific needs and get stuck again because this requires more advanced skills then the basic programming concepts I have been reading about on the learning guides. So, I am now feeling VERY frustrated and have no idea what on Earth I am doing! Can anyone please offer guidance in my learning process? I don't know how and what I should be spending my time learning first and/or if I should focus my learning towards the skill areas I will require to write my specific programmes, although I have no idea what these are. I would like advise on finding some really good interactive(let you know if your solution to an exercise is correct or not) and or video tutorials that give you feedback on the solutions you write to exercises. Many thanks in advance for all your help, it will be much appreciated! Cecilia Chavana-Bryant DPhil Candidate - Remote sensing and tropical phenology Environmental Change Institute School of Geography and the Environment University of Oxford South Parks Road, Oxford, OX1 3QY Web: http://www.eci.ox.ac.uk/teaching/doctoral/chavanabryantcecilia.php Tel Direct: +44 (0)1865 275861 Fax: +44 (0)1865 275885 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello Python Tutor - help please!
Hello, My highest recommendation for you is to start with a simple hello world program. Study that program, each line. Think about how and most importantly, why it works. Then, extend on it. Make it write to a file instead of a terminal. Then make it read from a file and print to the terminal. Then make it print one letter to each file, then read them back in and reconstruct the sentence. Just take it slow, and one step at a time. So many times people simply go for complex solutions and get lost in the complexity. Sorry for top posting. My phone client doesn't support inline replies. -Mario -- From: Cecilia Chavana-Bryant Sent: 8/22/2012 6:35 AM To: tutor@python.org Subject: [Tutor] Hello Python Tutor - help please! Dear all, I am just returning to my doctoral studies after a 7-month medical leave and desperately trying to catch up for lost time. I am COMPLETELY new to programming, well, I did try learning C for 3 weeks 3 yrs ago (with very little success) but had to stop and then spent 2 years in the Amazon climbing trees (lots more enjoyable than learning to programme!) and collecting loads of field data that I now need to post-process and analyse. By the way, the 3 weeks I spent trying to learn C really ended up being spent trying to get to grips with using a terminal for the first time in my life. Since getting back to work, I was advised to try learning Python instead of C as it is a much easier first language to learn. I have been trying, but again, to not great success. I started following A Primer on Scientific programming with Python but I kept getting lost and stuck, specially on the exercises. I have also been advised that I should not try to learn programming by following guides but by trying to write the programmes I need to analyse my data. Although I can understand the logic behind this last bit of advise (it gives context and direction to the learning process) I have also gotten stuck trying this approach as I do not know how to programme!. Thus, I was hoping that some of you can remember how you got started and point me towards any really good interactive learning guides/materials and/or have a good learning strategy for a complete beginner. I have searched the web and was overwhelmed by choice of tutorials and guides. I have skimmed through a couple of tutorials but then fail to see how all that relates to my own work and I get stuck with what seems like basic important concepts so I don't progress. I then think I should try to make some progress with my own data analysing and go back to trying to learn to write a programme for my specific needs and get stuck again because this requires more advanced skills then the basic programming concepts I have been reading about on the learning guides. So, I am now feeling VERY frustrated and have no idea what on Earth I am doing! Can anyone please offer guidance in my learning process? I don't know how and what I should be spending my time learning first and/or if I should focus my learning towards the skill areas I will require to write my specific programmes, although I have no idea what these are. I would like advise on finding some really good interactive(let you know if your solution to an exercise is correct or not) and or video tutorials that give you feedback on the solutions you write to exercises. Many thanks in advance for all your help, it will be much appreciated! Cecilia Chavana-Bryant DPhil Candidate - Remote sensing and tropical phenology Environmental Change Institute School of Geography and the Environment University of Oxford South Parks Road, Oxford, OX1 3QY Web: http://www.eci.ox.ac.uk/teaching/doctoral/chavanabryantcecilia.php Tel Direct: +44 (0)1865 275861 Fax: +44 (0)1865 275885 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello Python Tutor - help please!
If you don't have any prior programmers skills, i would advice first to learn the basics. You will need a good foundation, before it is possible to create complex functions. Starting with complex functions is only frustrating if you don't understand the basics. From: cecilia.chavana-bry...@ouce.ox.ac.uk To: tutor@python.org Date: Wed, 22 Aug 2012 10:10:46 + Subject: [Tutor] Hello Python Tutor - help please! Dear all, I am just returning to my doctoral studies after a 7-month medical leave and desperately trying to catch up for lost time. I am COMPLETELY new to programming, well, I did try learning C for 3 weeks 3 yrs ago (with very little success) but had to stop and then spent 2 years in the Amazon climbing trees (lots more enjoyable than learning to programme!) and collecting loads of field data that I now need to post-process and analyse. By the way, the 3 weeks I spent trying to learn C really ended up being spent trying to get to grips with using a terminal for the first time in my life. Since getting back to work, I was advised to try learning Python instead of C as it is a much easier first language to learn. I have been trying, but again, to not great success. I started following A Primer on Scientific programming with Python but I kept getting lost and stuck, specially on the exercises. I have also been advised that I should not try to learn programming by following guides but by trying to write the programmes I need to analyse my data. Although I can understand the logic behind this last bit of advise (it gives context and direction to the learning process) I have also gotten stuck trying this approach as I do not know how to programme!. Thus, I was hoping that some of you can remember how you got started and point me towards any really good interactive learning guides/materials and/or have a good learning strategy for a complete beginner. I have searched the web and was overwhelmed by choice of tutorials and guides. I have skimmed through a couple of tutorials but then fail to see how all that relates to my own work and I get stuck with what seems like basic important concepts so I don't progress. I then think I should try to make some progress with my own data analysing and go back to trying to learn to write a programme for my specific needs and get stuck again because this requires more advanced skills then the basic programming concepts I have been reading about on the learning guides. So, I am now feeling VERY frustrated and have no idea what on Earth I am doing! Can anyone please offer guidance in my learning process? I don't know how and what I should be spending my time learning first and/or if I should focus my learning towards the skill areas I will require to write my specific programmes, although I have no idea what these are. I would like advise on finding some really good interactive(let you know if your solution to an exercise is correct or not) and or video tutorials that give you feedback on the solutions you write to exercises. Many thanks in advance for all your help, it will be much appreciated! Cecilia Chavana-Bryant DPhil Candidate - Remote sensing and tropical phenology Environmental Change Institute School of Geography and the Environment University of Oxford South Parks Road, Oxford, OX1 3QY Web: http://www.eci.ox.ac.uk/teaching/doctoral/chavanabryantcecilia.php Tel Direct: +44 (0)1865 275861 Fax: +44 (0)1865 275885 ___ 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
Re: [Tutor] Hello Python Tutor - help please!
Hello Cecilia, My replies are below, interleaved with your comments, which are prefixed with marks. On 22/08/12 20:10, Cecilia Chavana-Bryant wrote: By the way, the 3 weeks I spent trying to learn C really ended up being spent trying to get to grips with using a terminal for the first time in my life. Unfortunately, there will be a certain amount of that, or at least something quite similar to a terminal. Fortunately, using Python in the terminal is usually MUCH easier than C, and in my experience using Python's interactive interpreter is one of the best ways to learn the language. What sort of computer are you using? Windows, Linux, Macintosh, or something different? I think that most of the people here use Linux or Windows, but we can probably help you one way or the other. Since getting back to work, I was advised to try learning Python instead of C as it is a much easier first language to learn. Yes, definitely, but it is still programming. Don't overestimate the difficulty, if it was hard programmers couldn't learn to do it *wink*, but on the other hand it's not trivial either. I have been trying, but again, to not great success. I started following A Primer on Scientific programming with Python but I kept getting lost and stuck, specially on the exercises. If you are willing to make a good, honest effort on the exercises first, we're happy to help you with them. We do like to see your attempt first, so that we can suggest fixes rather than solve the problem for you. I have also been advised that I should not try to learn programming by following guides but by trying to write the programmes I need to analyse my data. Although I can understand the logic behind this last bit of advise (it gives context and direction to the learning process) I have also gotten stuck trying this approach as I do not know how to programme!. I'm entirely with you there. Having direction in your learning is a good thing. But until you understand the basic skills you need, it will be nothing but frustration and pain! I recommend that, if nothing else, you work through some basic tutorials so that you at least have some idea of basic language constructs like: - strings - lists - functions - ints - floats - basic arithmetic - importing modules etc. You could start with the official Python tutorial: http://docs.python.org/tutorial/index.html although I find that it is sometimes a bit wordy. (I should talk...) If you get stuck, don't hesitate to come back and ask questions, that's why we're here. Thus, I was hoping that some of you can remember how you got started I learned from the book Learning Python by Mark Lutz and David Ascher, and then by writing oodles and oodles of really bad code which I have long since thrown away :) [...] So, I am now feeling VERY frustrated and have no idea what on Earth I am doing! Can anyone please offer guidance in my learning process? I feel your pain! That's how I feel every time I try to understand monads in Haskell (don't ask!). How about if you start off with a simple question you would like to solve using Python? Something relevant to your work. You may need to explain some of the concepts to us, since we're not ecologists. (At least, I'm not, I can't speak for others.) We can then try to guide you to a solution and introduce concepts as we go. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello Python Tutor - help please!
Hola Bill, Many thanks for your reply to my post, you seem to understand the predicament I am in very well. Unfortunately, I am currently working from home and do not have someone close by to help and this is why I came to this space. This is also why I asked for advise about interactive tutorials or video tutorials. I have found that I keep getting lost with the more traditional tutorials where you just read and then do exercises. Following the guide I mentioned on my initial post I got through the first 2 chapters but I found them quite hard going. I don't know if this makes me not a complete beginner but I certainly do not feel like I learned much from reading them. Maybe it is the trying to learn the computer ecosystem of terminal commands at the same time that is making this learning process so tough. With respect to my field data, during my 2 yrs of fieldwork I collected a large amount of data which is currently stored in excel files. My research involves remote sensing (data from Earth-observation satellites) and I work with data from the MODIS NASA satellite which monitors the health of forest canopies using reflectance data. My research is based in the Amazon. I have collected field data to monitor the leaf dynamics of canopy leaves during the dry season. Dry season is the time of year when many tropical trees change their old leaves for new ones. New leaves are more photosynthetically active (absorb more carbon from and release more oxygen into the atmosphere) so the leaf exchange of such a large forest region as the Amazon can have huge effects on regional and global carbon and water cycles and thus on global climate (apologies if I'm giving you loads more information than you need or requested?!). My data involves a large amount of data on leaf demography (we demographically surveyed more than 120,000 leaves), and thousands of morphological and reflectance measurements. I will have to reorganise this data and create a few easily manipulable datasets so I can sort data according to leaf age, canopy position, date, etc. Then I will have to do statistical analyses on the data. I will also have to model some of the data. Many thanks for taking the time to respond to my post so comprehensively and for your good wishes. Cecilia Chavana-Bryant DPhil Candidate - Remote sensing and tropical phenology Environmental Change Institute School of Geography and the Environment University of Oxford South Parks Road, Oxford, OX1 3QY Web: http://www.eci.ox.ac.uk/teaching/doctoral/chavanabryantcecilia.php Tel Direct: +44 (0)1865 275861 Fax: +44 (0)1865 275885 From: William R. Wing (Bill Wing) [w...@mac.com] Sent: 22 August 2012 15:17 To: Cecilia Chavana-Bryant Cc: William R. Wing (Bill Wing) Subject: Re: [Tutor] Hello Python Tutor - help please! On Aug 22, 2012, at 6:10 AM, Cecilia Chavana-Bryant cecilia.chavana-bry...@ouce.ox.ac.ukmailto:cecilia.chavana-bry...@ouce.ox.ac.uk wrote: Dear all, I am just returning to my doctoral studies after a 7-month medical leave and desperately trying to catch up for lost time. I am COMPLETELY new to programming, well, I did try learning C for 3 weeks 3 yrs ago (with very little success) but had to stop and then spent 2 years in the Amazon climbing trees (lots more enjoyable than learning to programme!) and collecting loads of field data that I now need to post-process and analyse. By the way, the 3 weeks I spent trying to learn C really ended up being spent trying to get to grips with using a terminal for the first time in my life. Could you say a few words about what the field data is, and how you hope to analyze it. That is, are you headed in the direction of plotting species density on maps, or the time evolution of something, or doing statistics? Since getting back to work, I was advised to try learning Python instead of C as it is a much easier first language to learn. I have been trying, but again, to not great success. I started following A Primer on Scientific programming with Python but I kept getting lost and stuck, specially on the exercises. I have also been advised that I should not try to learn programming by following guides but by trying to write the programmes I need to analyse my data. Although I can understand the logic behind this last bit of advise (it gives context and direction to the learning process) I have also gotten stuck trying this approach as I do not know how to programme!. Thus, I was hoping that some of you can remember how you got started and point me towards any really good interactive learning guides/materials and/or have a good learning strategy for a complete beginner. I have searched the web and was overwhelmed by choice of tutorials and guides. I have skimmed through a couple of tutorials but then fail to see how all that relates to my own work and I get stuck with what seems like basic important concepts so I don't progress. I then think I
Re: [Tutor] Hello Python Tutor - help please!
On Wed, Aug 22, 2012 at 11:33 AM, Cecilia Chavana-Bryant cecilia.chavana-bry...@ouce.ox.ac.uk wrote: Hola Bill, Many thanks for your reply to my post, you seem to understand the predicament I am in very well. Unfortunately, I am currently working from home and do not have someone close by to help and this is why I came to this space. This is also why I asked for advise about interactive tutorials or video tutorials. I have found that I keep getting lost with the more traditional tutorials where you just read and then do exercises. Following the guide I mentioned on my initial post I got through the first 2 chapters but I found them quite hard going. I don't know if this makes me not a complete beginner but I certainly do not feel like I learned much from reading them. Maybe it is the trying to learn the computer ecosystem of terminal commands at the same time that is making this learning process so tough. With respect to my field data, during my 2 yrs of fieldwork I collected a large amount of data which is currently stored in excel files. My research involves remote sensing (data from Earth-observation satellites) and I work with data from the MODIS NASA satellite which monitors the health of forest canopies using reflectance data. My research is based in the Amazon. I have collected field data to monitor the leaf dynamics of canopy leaves during the dry season. Dry season is the time of year when many tropical trees change their old leaves for new ones. New leaves are more photosynthetically active (absorb more carbon from and release more oxygen into the atmosphere) so the leaf exchange of such a large forest region as the Amazon can have huge effects on regional and global carbon and water cycles and thus on global climate (apologies if I'm giving you loads more information than you need or requested?!). My data involves a large amount of data on leaf demography (we demographically surveyed more than 120,000 leaves), and thousands of morphological and reflectance measurements. I will have to reorganise this data and create a few easily manipulable datasets so I can sort data according to leaf age, canopy position, date, etc. Then I will have to do statistical analyses on the data. I will also have to model some of the data. Many thanks for taking the time to respond to my post so comprehensively and for your good wishes. Cecilia Chavana-Bryant DPhil Candidate - Remote sensing and tropical phenology Environmental Change Institute School of Geography and the Environment University of Oxford South Parks Road, Oxford, OX1 3QY Web: http://www.eci.ox.ac.uk/teaching/doctoral/chavanabryantcecilia.php Tel Direct: +44 (0)1865 275861 Fax: +44 (0)1865 275885 From: William R. Wing (Bill Wing) [w...@mac.com] Sent: 22 August 2012 15:17 To: Cecilia Chavana-Bryant Cc: William R. Wing (Bill Wing) Subject: Re: [Tutor] Hello Python Tutor - help please! On Aug 22, 2012, at 6:10 AM, Cecilia Chavana-Bryant cecilia.chavana-bry...@ouce.ox.ac.uk wrote: Dear all, I am just returning to my doctoral studies after a 7-month medical leave and desperately trying to catch up for lost time. I am COMPLETELY new to programming, well, I did try learning C for 3 weeks 3 yrs ago (with very little success) but had to stop and then spent 2 years in the Amazon climbing trees (lots more enjoyable than learning to programme!) and collecting loads of field data that I now need to post-process and analyse. By the way, the 3 weeks I spent trying to learn C really ended up being spent trying to get to grips with using a terminal for the first time in my life. Could you say a few words about what the field data is, and how you hope to analyze it. That is, are you headed in the direction of plotting species density on maps, or the time evolution of something, or doing statistics? Since getting back to work, I was advised to try learning Python instead of C as it is a much easier first language to learn. I have been trying, but again, to not great success. I started following A Primer on Scientific programming with Python but I kept getting lost and stuck, specially on the exercises. I have also been advised that I should not try to learn programming by following guides but by trying to write the programmes I need to analyse my data. Although I can understand the logic behind this last bit of advise (it gives context and direction to the learning process) I have also gotten stuck trying this approach as I do not know how to programme!. Thus, I was hoping that some of you can remember how you got started and point me towards any really good interactive learning guides/materials and/or have a good learning strategy for a complete beginner. I have searched the web and was overwhelmed by choice of tutorials and guides. I have skimmed through a couple of tutorials but then fail to see how all that relates to my own work and I get
Re: [Tutor] Hello Python Tutor - help please!
On 22/08/12 11:10, Cecilia Chavana-Bryant wrote: I do not know how to programme!. Thus, I was hoping that some of you can remember how you got started and point me towards any really good interactive learning guides/materials and/or have a good learning strategy for a complete beginner. At the risk of self promotion you could try the early stages of my tutorial (see .sig). It starts from level zero and explains the concepts of programming before getting started writing code. I personally found that to be fundamental to my learning when I started (and why I included it!). It then goes through the basic programming structures using very simple examples - a multiplication table and address book mainly. (It includes VBScript and Javascript examples too but feel free to ignore them if you find they confuse more than help! The intent is to show the common structures present in all programming languages :-) Whether you progress beyond the first two sections depends on what you want to do next. Those would be enough to start writing programs related to your work and switching to another tutor at that point might be effective. But the concepts topics at the start of my tutor are I think relatively unique, and if diving straight into writing code isn't working maybe a view of the bigger picture will help. -- 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] Hello Python Tutor - help please!
Hi Cecilia, You've had a lot of good replies already, but I'd like to add the following points if I may: 1) You probably should figure out as much as that's possible up front exactly you're trying to do in terms of data processing first (e.g. some idea of the stats, graphs, summaries, operations etc), and then figure out whether Python is in fact the quickest/best way to get there for you. Python is very capable, it has many data analysis libraries and so on and is used by many scientists (NumPy, SciPy, Pandas comes to mind offhand), but then there are also many other languages and system also appropriate in this sphere. (R comes to mind.) Your goal (from my point of view) is not to become a programmer, but to get your research done. Python may be the way to achieve that, but from where I'm sitting it may also not be. 2) It may be useful to take some suitable courses from some of the very good free online courses now available from various sources such as Coursera. Some examples that seem relevant: Computing for Data Analysis: https://www.coursera.org/course/compdata Mathematics Biostatistics Boot camp: https://www.coursera.org/course/biostats Data Analysis https://www.coursera.org/course/dataanalysis There are also courses covering basic programming, including Python, for example: https://www.coursera.org/course/programming1 HTH, Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello Python Tutor - help please!
I highly recommend the Google Python class that is found on YouTube. The first video is found at http://www.youtube.com/watch?v=tKTZoB2Vjuk The supporting class materials and assignments are found at http://code.google.com/edu/languages/google-python-class/ . This series of videos begins at a pretty basic level, but subsequent videos increase the difficulty level pretty rapidly. Don't despair - the concept of how to properly manipulate strings, lists, tuples, and other objects is rather daunting, but if you're working on your doctoral studies, you already know that complex concepts aren't simply soaked up like water to a sponge ;). Ray On 08/22/2012 03:10 AM, Cecilia Chavana-Bryant wrote: Dear all, I am just returning to my doctoral studies after a 7-month medical leave and desperately trying to catch up for lost time. I am COMPLETELY new to programming, well, I did try learning C for 3 weeks 3 yrs ago (with very little success) but had to stop and then spent 2 years in the Amazon climbing trees (lots more enjoyable than learning to programme!) and collecting loads of field data that I now need to post-process and analyse. By the way, the 3 weeks I spent trying to learn C really ended up being spent trying to get to grips with using a terminal for the first time in my life. Since getting back to work, I was advised to try learning Python instead of C as it is a much easier first language to learn. I have been trying, but again, to not great success. I started following A Primer on Scientific programming with Python but I kept getting lost and stuck, specially on the exercises. I have also been advised that I should not try to learn programming by following guides but by trying to write the programmes I need to analyse my data. Although I can understand the logic behind this last bit of advise (it gives context and direction to the learning process) I have also gotten stuck trying this approach as I do not know how to programme!. Thus, I was hoping that some of you can remember how you got started and point me towards any really good interactive learning guides/materials and/or have a good learning strategy for a complete beginner. I have searched the web and was overwhelmed by choice of tutorials and guides. I have skimmed through a couple of tutorials but then fail to see how all that relates to my own work and I get stuck with what seems like basic important concepts so I don't progress. I then think I should try to make some progress with my own data analysing and go back to trying to learn to write a programme for my specific needs and get stuck again because this requires more advanced skills then the basic programming concepts I have been reading about on the learning guides. So, I am now feeling VERY frustrated and have no idea what on Earth I am doing! Can anyone please offer guidance in my learning process? I don't know how and what I should be spending my time learning first and/or if I should focus my learning towards the skill areas I will require to write my specific programmes, although I have no idea what these are. I would like advise on finding some really good interactive(let you know if your solution to an exercise is correct or not) and or video tutorials that give you feedback on the solutions you write to exercises. Many thanks in advance for all your help, it will be much appreciated! Cecilia Chavana-Bryant DPhil Candidate - Remote sensing and tropical phenology Environmental Change Institute School of Geography and the Environment University of Oxford South Parks Road, Oxford, OX1 3QY Web: http://www.eci.ox.ac.uk/teaching/doctoral/chavanabryantcecilia.php Tel Direct: +44 (0)1865 275861 Fax: +44 (0)1865 275885 ___ 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] Hello Python Tutor - help please!
Steven, (now from my new account without all the long-winded signature) can files be attached to posts in this forum? Cecilia ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello Python Tutor - help please!
On 22/08/12 22:51, Cecilia Chavana-Bryant wrote: Steven, (now from my new account without all the long-winded signature) can files be attached to posts in this forum? Yes they can, but we prefer if you just include them in the body if they are fairly short (100 lines?) or put them on a pastebin with a link. Some mail tools/servers/smartphones don't like mail attachments. -- 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] Hello Python Tutor - help please!
On 22/08/12 21:51, Cecilia Chavana-Bryant wrote: def main(fname, sheet_name): wb = xlrd.open_workbook(fname) sh = wb.sheet_by_name(sheet_name) data1 = sh.col_values(0) data2 = sh.col_values(1) return data1, data2 fname = Cal_File_P17.xlsx sheet_name = RefPanelData (data1, data2) = main(fname) print data1, data2 ... I do not know where the data is being saved to. That's because it isn't being saved anywhere, it gets thrown away after printing it. If you want to save it you need to augment/replace the print statement with a file write statement(s) You could also write it out using the OS redirection facility. On Unix (ie Your MacOS Terminal) thats done by running the program like: $ python myprog.py myOutputFile.txt Where you substitute your own desired program name and output filename of course! But that will just create a text file that looks like the output displayed on the Terminal, which is not, I think, what you are after. You probably want to do some extra work to save as a csv file. However, before you do that you could look at using the spreadsheet's SaveAs feature to export as a CSV directly, but it depends on how many spreadsheets you need to convert! 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
[Tutor] help--- opening csv in different functions
I am trying to fill a file. When i am start the leading fuction the file schould be overwriting the , probarly, existing csv file. Accoording from keys from different keys in my sql files, information is collected and written in a other function. I tried something like this code class BAGExtractPlus(wx.Frame): .. #-- # schrijven van de records #-- def schrijfExportRecord(self,identificatie, hoofdadres, verblijfobjectgeometrie, dag): ofile=open(r'D:\bestanden\BAG\adrescoordinaten.csv', 'wa') verblijfhoofd = csv.writer(ofile, delimiter=',', quotechar='', quoting=csv.QUOTE_NONNUMERIC) sql1=; sql1=Select huisnummer, huisletter, huisnummertoevoeging, postcode, gerelateerdeopenbareruimte from nummeraanduiding sql1a= where aanduidingrecordinactief 'J' and hsql1= einddatum ' + dag + ' and identificatie = ' + hoofdadres + '; sql1= sql1 + sql1a + hsql1; num= database.select(sql1); for row in num: huisnummer=row[0]; huisletter=row[1]; huisnummertoevoeging=row[2]; postcode=row[3]; gerelateerdeopenbareruimte=row[4]; sql2=Select openbareruimtenaam, gerelateerdewoonplaats from openbareruimte where aanduidingrecordinactief 'J' sql2= sql2 + and einddatum ' + dag + ' and identificatie = ' + gerelateerdeopenbareruimte + '; opn=database.select(sql2); for row in database.select(sql2): openbareruimtenaam=row[0]; gerelateerdewoonplaats=row[1]; sql3=Select woonplaatsnaam from woonplaats where aanduidingrecordinactief 'J' sql3= sql3 + and einddatum ' + dag + ' and identificatie = ' + gerelateerdewoonplaats + '; wpl=database.select(sql3); for row in wpl: woonplaatsnaam=row[0]; newrow=[identificatie, verblijfobjectgeometrie, huisnummer, huisletter, huisnummertoevoeging, postcode,openbareruimtenaam, woonplaatsnaam]; verblijfhoofd.writerow(newrow); del wpl[:]; del opn[:]; del num[:]; #-- # Exporteer benodigde gegevens #-- def ExportBestanden(self, event): ofile=open(r'D:\bestanden\BAG\adrescoordinaten.csv', 'wb') verblijfhoofd = csv.writer(ofile, delimiter=',', quotechar='', quoting=csv.QUOTE_NONNUMERIC) dag=str(datetime.date.today()); sql4=Select adresseerbaarobjectnevenadres.identificatie, adresseerbaarobjectnevenadres.nevenadres from adresseerbaarobjectnevenadres where aanduidingrecordinactief 'J' order by adresseerbaarobjectnevenadres.identificatie neven= database.select(sql4); for row in neven: nidentificatie=row[0]; nevenadres=row[1]; sql=Select identificatie, hoofdadres, ligplaatsgeometrie from ligplaats where aanduidingrecordinactief 'J' and einddatum ' + dag + ' and identificatie = '+ nidentificatie + ' lig= database.select(sql); for row in lig: hoofdadres=nevenadres; identificatie=row[0]; verblijfobjectgeometrie=row[2]; self.schrijfExportRecord(identificatie, hoofdadres, verblijfobjectgeometrie, dag) sql=Select identificatie, hoofdadres, verblijfsobjectgeometrie from verblijfsobject where aanduidingrecordinactief 'J' and einddatum ' + dag + ' and identificatie = '+ nidentificatie + ' vbo= database.select(sql); for row in vbo: hoofdadres=row[1]; identificatie=row[0]; verblijfobjectgeometrie=row[2]; self.schrijfExportRecord(identificatie, hoofdadres, verblijfobjectgeometrie, dag) sql=Select identificatie, hoofdadres, standplaatsgeometrie from standplaats where aanduidingrecordinactief 'J' and einddatum ' + dag + ' and identificatie = '+ nidentificatie + ' stand= database.select(sql); for row in stand: hoofdadres=nevenadres; identificatie=row[0]; verblijfobjectgeometrie=row[2]; self.schrijfExportRecord(identificatie, hoofdadres, verblijfobjectgeometrie, dag) del stand[:]; del vbo[:]; del lig[:]; del neven[:]; sql=Select identificatie, hoofdadres, ligplaatsgeometrie from ligplaats where aanduidingrecordinactief 'J' and einddatum ' + dag + ' lig= database.select(sql); for row in lig:
Re: [Tutor] help--- opening csv in different functions
On 08/10/2012 06:02 AM, leon zaat wrote: I am trying to fill a file. When i am start the leading fuction the file schould be overwriting the , probarly, existing csv file. Accoording from keys from different keys in my sql files, information is collected and written in a other function. I tried something like this code class BAGExtractPlus(wx.Frame): .. #-- # schrijven van de records #-- def schrijfExportRecord(self,identificatie, hoofdadres, verblijfobjectgeometrie, dag): ofile=open(r'D:\bestanden\BAG\adrescoordinaten.csv', 'wa') verblijfhoofd = csv.writer(ofile, delimiter=',', quotechar='', quoting=csv.QUOTE_NONNUMERIC) sql1=; sql1=Select huisnummer, huisletter, huisnummertoevoeging, postcode, gerelateerdeopenbareruimte from nummeraanduiding sql1a= where aanduidingrecordinactief 'J' and hsql1= einddatum ' + dag + ' and identificatie = ' + hoofdadres + '; sql1= sql1 + sql1a + hsql1; num= database.select(sql1); for row in num: huisnummer=row[0]; huisletter=row[1]; huisnummertoevoeging=row[2]; postcode=row[3]; gerelateerdeopenbareruimte=row[4]; sql2=Select openbareruimtenaam, gerelateerdewoonplaats from openbareruimte where aanduidingrecordinactief 'J' sql2= sql2 + and einddatum ' + dag + ' and identificatie = ' + gerelateerdeopenbareruimte + '; opn=database.select(sql2); for row in database.select(sql2): openbareruimtenaam=row[0]; gerelateerdewoonplaats=row[1]; sql3=Select woonplaatsnaam from woonplaats where aanduidingrecordinactief 'J' sql3= sql3 + and einddatum ' + dag + ' and identificatie = ' + gerelateerdewoonplaats + '; wpl=database.select(sql3); for row in wpl: woonplaatsnaam=row[0]; newrow=[identificatie, verblijfobjectgeometrie, huisnummer, huisletter, huisnummertoevoeging, postcode,openbareruimtenaam, woonplaatsnaam]; verblijfhoofd.writerow(newrow); del wpl[:]; del opn[:]; del num[:]; #-- # Exporteer benodigde gegevens #-- def ExportBestanden(self, event): ofile=open(r'D:\bestanden\BAG\adrescoordinaten.csv', 'wb') verblijfhoofd = csv.writer(ofile, delimiter=',', quotechar='', quoting=csv.QUOTE_NONNUMERIC) dag=str(datetime.date.today()); sql4=Select adresseerbaarobjectnevenadres.identificatie, adresseerbaarobjectnevenadres.nevenadres from adresseerbaarobjectnevenadres where aanduidingrecordinactief 'J' order by adresseerbaarobjectnevenadres.identificatie neven= database.select(sql4); for row in neven: nidentificatie=row[0]; nevenadres=row[1]; sql=Select identificatie, hoofdadres, ligplaatsgeometrie from ligplaats where aanduidingrecordinactief 'J' and einddatum ' + dag + ' and identificatie = '+ nidentificatie + ' lig= database.select(sql); for row in lig: hoofdadres=nevenadres; identificatie=row[0]; verblijfobjectgeometrie=row[2]; self.schrijfExportRecord(identificatie, hoofdadres, verblijfobjectgeometrie, dag) sql=Select identificatie, hoofdadres, verblijfsobjectgeometrie from verblijfsobject where aanduidingrecordinactief 'J' and einddatum ' + dag + ' and identificatie = '+ nidentificatie + ' vbo= database.select(sql); for row in vbo: hoofdadres=row[1]; identificatie=row[0]; verblijfobjectgeometrie=row[2]; self.schrijfExportRecord(identificatie, hoofdadres, verblijfobjectgeometrie, dag) sql=Select identificatie, hoofdadres, standplaatsgeometrie from standplaats where aanduidingrecordinactief 'J' and einddatum ' + dag + ' and identificatie = '+ nidentificatie + ' stand= database.select(sql); for row in stand: hoofdadres=nevenadres; identificatie=row[0]; verblijfobjectgeometrie=row[2]; self.schrijfExportRecord(identificatie, hoofdadres, verblijfobjectgeometrie, dag) del stand[:]; del vbo[:]; del lig[:]; del neven[:]; sql=Select identificatie, hoofdadres, ligplaatsgeometrie
Re: [Tutor] help--- opening csv in different functions
On 10/08/12 11:02, leon zaat wrote: I am trying to fill a file. I assume you mean create a file? Or overwrite an existing one? Or append to an existing one. There isn't really a concept of filling a file, they just keep getting bigger until you ruin out of space. (There are some filesystems that support creating fixed size files but they are very marginal cases) The seems to work, but after 200.00 entries i got the message that opening is not allowed. What i am doing wrong? You shouldn't be continually opening the file... And when you do you should be sure to close it again as soon as possible. Is there a way to open the file once. Yes that's usually what you would do. Open it, collect your data and write it out (either as you collect it or all at once as you prefer) then close the file. When i didn't open it in the first part, it said it couldn't find the file. Not sure what that means but if you haven't created it any attempt to read it will fail. But your code was way too long for me to be bothered reading through, sorry. -- 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] help - SyntaxError: Non-UTF-8 code using python 3
On 09/08/12 04:26, Lily Tran wrote: I am getting the following error when I try to run this python program in eclipse. I am running python 3: I see you fixed that,but there are other problems: def MagicEightBallEmulator(): answers = [As I see it, yes, Very doubtful] while True: what = random.choice(answers) This loop will go on forever. I don't think you want a loop here you just want to select a choice once. return print(what) print is a function which returns None. So your function returns None. Youcan therefore eiother dispense with the return statement and Python will return None as default, or, as better practice, return what and put the print() call in your main function: MagicEightBallEmulator() becomes print( MagicEightBallEmulator() ) 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] help -Global name xxxxxxxx is not definied.
Hello everyone, Can anybody help me with this problem. Ik have a program that i' am modifying. Ik build a function to export data to a csv file. I tried the functions over different parts, that needed to be extracted. The parts on it self worked fine. Now I put all parts in my function. Because there was a sections that was all alike for the parts, i thought to put it in a second function. This is the code I written: #-- # schrijven van de records #-- def schrijfExportRecord(): sql1=; sql1=Select huisnummer, huisletter, huisnummertoevoeging, postcode, gerelateerdeopenbareruimte from nummeraanduiding sql1a= where aanduidingrecordinactief 'J' and hsql1= einddatum ' + dag + ' and identificatie = ' + hoofdadres + '; sql1= sql1 + sql1a + hsql1; num= database.select(sql1); for row in num: huisnummer=row[0]; huisletter=row[1]; huisnummertoevoeging=row[2]; postcode=row[3]; gerelateerdeopenbareruimte=row[4]; sql2=Select openbareruimtenaam, gerelateerdewoonplaats from openbareruimte where aanduidingrecordinactief 'J' sql2= sql2 + and einddatum ' + dag + ' and identificatie = ' + gerelateerdeopenbareruimte + '; opn=database.select(sql2); for row in database.select(sql2): openbareruimtenaam=row[0]; gerelateerdewoonplaats=row[1]; sql3=Select woonplaatsnaam from woonplaats where aanduidingrecordinactief 'J' sql3= sql3 + and einddatum ' + dag + ' and identificatie = ' + gerelateerdewoonplaats + '; wpl=database.select(sql3); for row in wpl: woonplaatsnaam=row[0]; newrow=[identificatie, verblijfobjectgeometrie, huisnummer, huisletter, huisnummertoevoeging, postcode,openbareruimtenaam, woonplaatsnaam]; verblijfhoofd.writerow(newrow); del wpl[:]; del opn[:]; del num[:]; #-- # Exporteer benodigde gegevens #-- def ExportBestanden(self, event): ofile=open(r'D:\bestanden\BAG\adrescoordinaten.csv', 'wb') verblijfhoofd = csv.writer(ofile, delimiter=',', quotechar='', quoting=csv.QUOTE_NONNUMERIC) dag=str(datetime.date.today()); sql4=Select adresseerbaarobjectnevenadres.identificatie, adresseerbaarobjectnevenadres.nevenadres from adresseerbaarobjectnevenadres where aanduidingrecordinactief 'J' order by adresseerbaarobjectnevenadres.identificatie neven= database.select(sql4); for row in neven: nidentificatie=row[0]; nevenadres=row[1]; sql=Select identificatie, hoofdadres, ligplaatsgeometrie from ligplaats where aanduidingrecordinactief 'J' and einddatum ' + dag + ' and identificatie = '+ nidentificatie + ' lig= database.select(sql); for row in lig: hoofdadres=nevenadres; identificatie=row[0]; verblijfobjectgeometrie=row[2]; schrijfExportRecord(identificatie, hoofdadres, verblijfobjectgeometrie) sql=Select identificatie, hoofdadres, verblijfsobjectgeometrie from verblijfsobject where aanduidingrecordinactief 'J' and einddatum ' + dag + ' and identificatie = '+ nidentificatie + ' vbo= database.select(sql); for row in vbo: hoofdadres=row[1]; identificatie=row[0]; verblijfobjectgeometrie=row[2]; schrijfExportRecord(identificatie, hoofdadres, verblijfobjectgeometrie) sql=Select identificatie, hoofdadres, standplaatsgeometrie from standplaats where aanduidingrecordinactief 'J' and einddatum ' + dag + ' and identificatie = '+ nidentificatie + ' stand= database.select(sql); for row in stand: hoofdadres=nevenadres; identificatie=row[0]; verblijfobjectgeometrie=row[2]; schrijfExportRecord(identificatie, hoofdadres, verblijfobjectgeometrie) del stand[:]; del vbo[:]; del lig[:]; del neven[:]; sql=Select identificatie, hoofdadres, ligplaatsgeometrie from ligplaats where aanduidingrecordinactief 'J' and einddatum ' + dag + ' lig= database.select(sql); for row in lig: hoofdadres=row[1]; identificatie=row[0]; verblijfobjectgeometrie=row[2]; schrijfExportRecord() del lig[:]; sql=Select
Re: [Tutor] help -Global name xxxxxxxx is not definied.
leon zaat wrote: Hello everyone, Can anybody help me with this problem. Ik have a program that i' am modifying. Ik build a function to export data to a csv file. I tried the functions over different parts, that needed to be extracted. The parts on it self worked fine. Now I put all parts in my function. Because there was a sections that was all alike for the parts, i thought to put it in a second function. This is the code I written: # schrijven van de records def schrijfExportRecord(): sql1=; ... def ExportBestanden(self, event): ofile=open(r'D:\bestanden\BAG\adrescoordinaten.csv', 'wb') ... When i run the program i got the following message: NameError: global name 'schrijfExportRecord' is not found What I am doing wrong and how can i fix it? Judging from the indentation and the 'self' argument the code you quote is inside a class, e. g. class Whatever: def schrijfExportRecord(): ... def ExportBestanden(self, event): ... This layout makes shrijfExportRecord() a method and you have to (1) add a self argument: def schrijfExportRecord(self): ... (2) invoke it in other methods as self.schrijfExportRecord() Alternatively you can leave it as is and move it out of the class (don't forget to fix the indentation accordingly): def schrijfExportRecord(): ... class Whatever: def ExportBestanden(self, event): ... By the way del wpl[:]; is probably cargo cult (the code has no effect) because the list is garbage-collected at the end of the function anyway. Also, in Python you don't need to place a ';' at the end of a statement unless you put multiple statements into one line (which is discouraged). ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] help -Global name xxxxxxxx is not definied.
Thanks, adding the self as suggested did the trick. To: tutor@python.org From: __pete...@web.de Date: Thu, 9 Aug 2012 14:45:58 +0200 Subject: Re: [Tutor] help -Global name is not definied. leon zaat wrote: Hello everyone, Can anybody help me with this problem. Ik have a program that i' am modifying. Ik build a function to export data to a csv file. I tried the functions over different parts, that needed to be extracted. The parts on it self worked fine. Now I put all parts in my function. Because there was a sections that was all alike for the parts, i thought to put it in a second function. This is the code I written: # schrijven van de records def schrijfExportRecord(): sql1=; ... def ExportBestanden(self, event): ofile=open(r'D:\bestanden\BAG\adrescoordinaten.csv', 'wb') ... When i run the program i got the following message: NameError: global name 'schrijfExportRecord' is not found What I am doing wrong and how can i fix it? Judging from the indentation and the 'self' argument the code you quote is inside a class, e. g. class Whatever: def schrijfExportRecord(): ... def ExportBestanden(self, event): ... This layout makes shrijfExportRecord() a method and you have to (1) add a self argument: def schrijfExportRecord(self): ... (2) invoke it in other methods as self.schrijfExportRecord() Alternatively you can leave it as is and move it out of the class (don't forget to fix the indentation accordingly): def schrijfExportRecord(): ... class Whatever: def ExportBestanden(self, event): ... By the way del wpl[:]; is probably cargo cult (the code has no effect) because the list is garbage-collected at the end of the function anyway. Also, in Python you don't need to place a ';' at the end of a statement unless you put multiple statements into one line (which is discouraged). ___ 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
Re: [Tutor] help -Global name xxxxxxxx is not definied.
On 09/08/12 13:20, leon zaat wrote: When i run the program i got the following message: NameError: global name 'schrijfExportRecord' is not found What I am doing wrong and how can i fix it? Looks like you found the problem in this case but for future reference... Please, always post the entire error message not just the last line. It will usually show us which line it is complaining about and the call stack surrounding it. All very helpful in locating the source of the problem. -- 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
[Tutor] help - SyntaxError: Non-UTF-8 code using python 3
Hello; I am getting the following error when I try to run this python program in eclipse. I am running python 3: File /Users/lilytran/Desktop/python/Ex_Files_Python_3_EssT/Exercise Files/class_beginner_python/hw3_2_lab6.py, line 30 SyntaxError: Non-UTF-8 code starting with '\xd0' in file on line 30, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details Can you please tell me what I am doing wrong and how do I fix this error? Below is my program. Thanks –Lily import random def MagicEightBallEmulator(): answers = [As I see it, yes, It is certain, It is decidedly so, Most likely, Outlook good, Signs point to yes, Without a doubt, Yes, Yes – definitely, You may rely on it, Reply hazy, try again, Ask again later, Better not tell you now, Do not count on it, My reply is no, My sources say no, Outlook not so good, Very doubtful] while True: what = random.choice(answers) return print(what) def RunEmulator(): while True: print ('Welcome to Magic 8 Ball!') print ('Please ask your question!') question = input() if question == 'quit': break MagicEightBallEmulator() RunEmulator() ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] help - SyntaxError: Non-UTF-8 code using python 3
On 08/08/2012 11:26 PM, Lily Tran wrote: Hello; I am getting the following error when I try to run this python program in eclipse. I am running python 3: File /Users/lilytran/Desktop/python/Ex_Files_Python_3_EssT/Exercise Files/class_beginner_python/hw3_2_lab6.py, line 30 SyntaxError: Non-UTF-8 code starting with '\xd0' in file on line 30, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details Can you please tell me what I am doing wrong and how do I fix this error? Below is my program. Thanks –Lily import random def MagicEightBallEmulator(): SNIP what = random.choice(answers) return print(what) def RunEmulator(): while True: print ('Welcome to Magic 8 Ball!') print ('Please ask your question!') question = input() if question == 'quit': break MagicEightBallEmulator() RunEmulator() Sending us the source without adding a comment to line #30 seems a bit presumptuous. Double spacing by sending it as a non-text message makes it worse. The error message itself seems pretty clear. You have a non-UTF8 sequence in a source file implicitly declared as being UTF8. Simplest solution? Don't use non-ASCII characters. You are probably entering some character (perhaps 0x00D0) encoded in some other form, and the compiler cannot decode it because it's not in UTF-8. How might you have gotten an non-ASCII character? It might be on your keyboard, like an o with an umlaut. Or you might have pasted it from a word processing document or a pdf file, like a smart quote. Better solution? Use a text editor that understands encodings, and set it to always use UTF-8. Another solution? Figure out what encoding your editor is stuck in, and declare that in your python file, as the second line. Final solutions? Use a hex viewer to search the file for that D0 mentioned, and figure out just where in your source it is. There's no reason to assume we could even see it here, since your message is encoded in Windows-1252. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] help - SyntaxError: Non-UTF-8 code using python 3
Thanks. I found the problem character and was able to resolve it. Lily On 8/8/12 10:10 PM, Dave Angel d...@davea.name wrote: On 08/08/2012 11:26 PM, Lily Tran wrote: Hello; I am getting the following error when I try to run this python program in eclipse. I am running python 3: File /Users/lilytran/Desktop/python/Ex_Files_Python_3_EssT/Exercise Files/class_beginner_python/hw3_2_lab6.py, line 30 SyntaxError: Non-UTF-8 code starting with '\xd0' in file on line 30, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details Can you please tell me what I am doing wrong and how do I fix this error? Below is my program. Thanks Lily import random def MagicEightBallEmulator(): SNIP what = random.choice(answers) return print(what) def RunEmulator(): while True: print ('Welcome to Magic 8 Ball!') print ('Please ask your question!') question = input() if question == 'quit': break MagicEightBallEmulator() RunEmulator() Sending us the source without adding a comment to line #30 seems a bit presumptuous. Double spacing by sending it as a non-text message makes it worse. The error message itself seems pretty clear. You have a non-UTF8 sequence in a source file implicitly declared as being UTF8. Simplest solution? Don't use non-ASCII characters. You are probably entering some character (perhaps 0x00D0) encoded in some other form, and the compiler cannot decode it because it's not in UTF-8. How might you have gotten an non-ASCII character? It might be on your keyboard, like an o with an umlaut. Or you might have pasted it from a word processing document or a pdf file, like a smart quote. Better solution? Use a text editor that understands encodings, and set it to always use UTF-8. Another solution? Figure out what encoding your editor is stuck in, and declare that in your python file, as the second line. Final solutions? Use a hex viewer to search the file for that D0 mentioned, and figure out just where in your source it is. There's no reason to assume we could even see it here, since your message is encoded in Windows-1252. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help please!
print Mum is in a %s mood % (mum_mood) print Dad is in a %s mood % (dad_mood) Hi Victoria! Since you have only one format character in the strings above there is no need to surround the variables mum_mood and dad_mood with parenthesis. You only do that when you have multiple formats in your string that print multiple variables. Ex: print Hi %s! You like %s and %s (user_name, x, y) ___ 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
Re: [Tutor] Help please!
On Tue, Jul 31, 2012 at 5:52 AM, ttmticdi . ttmti...@gmail.com wrote: print Mum is in a %s mood % (mum_mood) print Dad is in a %s mood % (dad_mood) Hi Victoria! Since you have only one format character in the strings above there is no need to surround the variables mum_mood and dad_mood with parenthesis. You only do that when you have multiple formats in your string that print multiple variables. Ex: No! print Hi %s! You like %s and %s (user_name, x, y) Yes! print Hi %s! You like %s and %s % (user_name, x, y) ___ 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 -- Joel Goldstick ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help please!
Ex: No! print Hi %s! You like %s and %s (user_name, x, y) Yes! print Hi %s! You like %s and %s % (user_name, x, y) Forgot the interpolation operator(%). Thank you very much Joel for correcting me. Regards, ttmticdi. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help please!
Hi! I am a new Python user, and would really appreciate some help. My code is as follows: from sys import argvs script, mum_mood, dad_mood = argvs # my own function def dad_and_mum_mood(mum_mood, dad_mood): print If both mum and dad are in a good mood, all is good. print If one is and one isn't, all is good. print If both are in a bad mood, not so good. print Mum is in a %s mood % (mum_mood) print Dad is in a %s mood % (dad_mood) print Where does that leave us? dad_and_mum_mood(mum_mood, dad_mood) I am just trying to get get the information mum_mood and dad_mood from the argvs (written into the command line), but I get the error ImportError: cannot import name argvs. Do you have any idea why this wouldn't be working? Thank you so much for helping me. Kind regards, Victoria ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help please!
On Mon, Jul 30, 2012 at 9:35 PM, Victoria Homsy victoriaho...@yahoo.com wrote: Hi! I am a new Python user, and would really appreciate some help. My code is as follows: from sys import argvs script, mum_mood, dad_mood = argvs # my own function def dad_and_mum_mood(mum_mood, dad_mood): print If both mum and dad are in a good mood, all is good. print If one is and one isn't, all is good. print If both are in a bad mood, not so good. print Mum is in a %s mood % (mum_mood) print Dad is in a %s mood % (dad_mood) print Where does that leave us? dad_and_mum_mood(mum_mood, dad_mood) I am just trying to get get the information mum_mood and dad_mood from the argvs (written into the command line), but I get the error ImportError: cannot import name argvs. The problem is exactly what the error message says. argvs should really be argv. HTH, Puneeth ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help please!
Hello all! I have a very simple question but I'm very new to python. Could you describe to me what the following piece of Python code says in English please? def print_a_line(line_count, f): print line_count, f.readline() I understand that line_count counts the number of lines in the Python prog, and that we are creating a function, and that 'f' stands for file etc, but I can't get my head around what the function does. Many thanks in advance! Best, Victoria___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help please!
On 7/30/2012 12:52 PM Victoria Homsy said... Hello all! I have a very simple question but I'm very new to python. Could you describe to me what the following piece of Python code says in English please? def print_a_line(line_count, f): print line_count, f.readline() This function accepts two passed parameters, then prints the first, and reads and prints one line from the second. Obviously, to work the first must be printable, and the second must provide a readline method. *IF* you believe that the names selected accurately represent the intent of the function, you may come to the type of conclusions you reach below. Emile I understand that line_count counts the number of lines in the Python prog, and that we are creating a function, and that 'f' stands for file etc, but I can't get my head around what the function does. Many thanks in advance! Best, Victoria ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help please!
Hello all! I have a very simple question but I'm very new to python. Could you describe to me what the following piece of Python code says in English please? Welcome to the list and Python! When posting code in the future I recommend posting in plain text and not rich text or HTML. If you are using Yahoo! via web interface you can do this by the following link. http://www.emailquestions.com/yahoo-mail/4446-switch-yahoo-mail-between-rich-text-plain-text.html def print_a_line(line_count, f): print line_count, f.readline() I understand that line_count counts the number of lines in the Python prog, and that we are creating a function, and that 'f' stands for file etc, but I can't get my head around what the function does. line_count in this function can be anything. It is not actually doing any counting or any work. All this function does is print whatever information is in line_count (I assume it would be the current line number), then it retrieves exactly one line from the file f and then prints that line. Let us assume that the following multi-line string is what is contained in file f. Some examples of what this function would print are shown below. '''This is the first line. And this is the second line. ''' print_a_line(1, f ) 1 This is the first line. print_a_line('line 2:', f ) line 2: And this is the second line. Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Matplotlib labels
On 19/06/2012 00:46, Alan Gauld wrote: On 19/06/12 00:13, Sean Carolan wrote: and not the total of all the individual items. Anyone matplotlib experts out there who can weigh in? Not me, but I notice there is a gmane newsfeed for matplotlib: gmane.comp.python.matplotlib.general Probably worth posting questions there. No probably about it, I've asked questions there and like all Python lists found them extremely friendly and helpful. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help with Matplotlib labels
I'm working on a simple python web app that generates graphs, because managers love graphs. I've got it about 90% done, but I'm having trouble getting labels onto my stacked graph. In the matplotlib documentation there is a nice example showing how to create the legend. Note how the variables p1 and p2 are used to generate the legend in this example: http://matplotlib.sourceforge.net/examples/pylab_examples/bar_stacked.html code p1 = plt.bar(ind, menMeans, width, color='r', yerr=womenStd) p2 = plt.bar(ind, womenMeans, width, color='y', bottom=menMeans, yerr=menStd) plt.ylabel('Scores') plt.title('Scores by group and gender') plt.xticks(ind+width/2., ('G1', 'G2', 'G3', 'G4', 'G5') ) plt.yticks(np.arange(0,81,10)) plt.legend( (p1[0], p2[0]), ('Men', 'Women') ) /code Unfortunately my graph is generated dynamically. How can I create my legend when my 'bar' objects have no names to refer to? for admin in bd: bar(ind, bd[admin], width, color=colordict[admin]) xticks(ind+width/2., datenames) legend() grid('on') outfile = 'testfile.png' savefig('/var/www/'+outfile) return outfile ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Matplotlib labels
Unfortunately my graph is generated dynamically. How can I create my legend when my 'bar' objects have no names to refer to? I also noticed another issue with my stacked bar graph; the total height of the bar is the size of the largest number of the dataset, and not the total of all the individual items. Anyone matplotlib experts out there who can weigh in? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Matplotlib labels
On 19/06/12 00:13, Sean Carolan wrote: and not the total of all the individual items. Anyone matplotlib experts out there who can weigh in? Not me, but I notice there is a gmane newsfeed for matplotlib: gmane.comp.python.matplotlib.general Probably worth posting questions there. -- 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] Help with Matplotlib labels
Not me, but I notice there is a gmane newsfeed for matplotlib: gmane.comp.python.matplotlib.general Probably worth posting questions there. Thank you, I will inquire on the newsfeed. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Matplotlib labels
Unfortunately my graph is generated dynamically. How can I create my legend when my 'bar' objects have no names to refer to? for admin in bd: bar(ind, bd[admin], width, color=colordict[admin]) xticks(ind+width/2., datenames) legend() grid('on') outfile = 'testfile.png' savefig('/var/www/'+outfile) return outfile I found the solution to this problem, one of the optional kwargs for the pyplyt.bar() function is label. Once I assigned that, legend() worked fine. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Matplotlib labels
I also noticed another issue with my stacked bar graph; the total height of the bar is the size of the largest number of the dataset, and not the total of all the individual items. Anyone matplotlib experts out there who can weigh in? I figured out what was going on here; the bars were all rendering on top of one another. Adjustments to the bottom parameter have fixed the issue. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help with graphics please
I request help in locating the graphics module graphics.py I am new to both programming and Python. I have successfully down loaded Python 2.7.2 and WingIde 101 4.1. I am using Windows 7 as my operating system. I am reading Python programming by John Zelle supplemented by MIT lectures on computing science. I have reached the chapter on Objects and Graphics. my problem is that I can not locate either the graphics module or graphics.py. the command import graphics elicits the response module unknown. I would be very appreciative of help in locating the file on the Internet. Naturally I will be pleased to purchase the file if necessary. regards, Ivor Surveyor isurve...@vianet.net.au ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with graphics please
On Tue, Apr 24, 2012 at 03:57:58PM +0800, Ivor Surveyor wrote: I request help in locating the graphics module graphics.py Have you tried searching for Python programming by John Zelle graphics.py on any of the major search engines, like Google, Yahoo or DuckDuckGo? That should always be your first stop for any question. I believe that this will give you the file you are after: http://mcsp.wartburg.edu/zelle/python/ the command import graphics elicits the response module unknown. No it doesn't. If you're going to learn programming, you will need to be pedantic about reporting the *precise* error messages you get, and not paraphrase them. The error message you get is almost certainly something like this: Traceback (most recent call last): File stdin, line 1, in module ImportError: No module named graphics (although the middle line is probably different). Now in this case I knew what you meant, it wasn't terribly difficult to work that out. But believe me, there are people who come here, or on other mailing lists and help forums, and give utterly undecipherable, incomplete, or even incorrect error messages, and thus send us on a wild goose chase trying to solve a problem that doesn't exist. Good luck and have fun! -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help with graphic file
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] Type help, copyright, credits or license for more information. Dear Steven D'Aprano I am most grateful for you directing me towards the file graphics.py. I was able to download the file and inserted a copy into the directory containing Python. So far so good. I then run WIngIDE and typed import python into the editor followed by run in the Python shell. Below is a copy of the error message. It seems that files related to tkinter are not properly installed including Tcl. Can you please give me advice on how to correct this. Below I have copied the full details of the message from Python and below that the details of my system.\: import graphics Traceback (most recent call last): File C:\Program Files (x86)\Wing_IDLE_PYTHON\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py, line 1, in module # Used internally for debug sandbox under external interpreter File C:\Program Files (x86)\graphics.py, line 168, in module _root = tk.Tk() File C:\Program Files (x86)\Lib\tkinter\__init__.py, line 1674, in __init__ self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) _tkinter.TclError: Can't find a usable init.tcl in the following directories: {C:\Program Files (x86)\tcl\tcl8.5} {C:/Program Files (x86)/lib/tcl8.5} C:/lib/tcl8.5 C:/lib/tcl8.5 C:/library C:/library C:/tcl8.5.9/library C:/tcl8.5.9/library C:/Program Files (x86)/tcl/tcl8.5/init.tcl: version conflict for package Tcl: have 8.5.9, need exactly 8.5.2 version conflict for package Tcl: have 8.5.9, need exactly 8.5.2 while executing package require -exact Tcl 8.5.2 (file C:/Program Files (x86)/tcl/tcl8.5/init.tcl line 20) invoked from within source {C:/Program Files (x86)/tcl/tcl8.5/init.tcl} (uplevel body line 1) invoked from within uplevel #0 [list source $tclfile] This probably means that Tcl wasn't installed properly. System Information report written at: 09/19/10 18:02:13 System Name: IVOR-PC [System Summary] ItemValue OS Name Microsoft Windows 7 Professional Version 6.1.7600 Build 7600 Other OS DescriptionNot Available OS Manufacturer Microsoft Corporation System Name IVOR-PC System Manufacturer MSI System ModelMS-7636 System Type x64-based PC Processor Intel(R) Core(TM) i5 CPU 750 @ 2.67GHz, 2668 Mhz, 4 Core(s), 4 Logical Processor(s) BIOS Version/Date American Megatrends Inc. V1.3, 21/12/2009 SMBIOS Version 2.6 Windows Directory C:\Windows System DirectoryC:\Windows\system32 Boot Device \Device\HarddiskVolume1 Locale Australia Hardware Abstraction Layer Version = 6.1.7600.16385 User Name Ivor-PC\Ivor Time Zone W. Australia Standard Time Installed Physical Memory (RAM) 4.00 GB Total Physical Memory 3.96 GB Available Physical Memory 2.81 GB Total Virtual Memory7.92 GB Available Virtual Memory6.24 GB Page File Space 3.96 GB Page File C:\pagefile.sys Kind regards and thank you agian for assistance Ivor Surveyor isurve...@vianet.net.au ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help with regular expression
Dear all Can someone please tell me how to solve the following problem. I have developed a python code to extract specific information from more than 1000 files which have slightly different format. The problem I am facing is that I have to develop specific RE for each of the file which is very difficult when it comes to handle 1000s of files. can someone please tell me how to solve this problem. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with regular expression
syed zaidi wrote: Dear all Can someone please tell me how to solve the following problem. I have developed a python code to extract specific information from more than 1000 files which have slightly different format. The problem I am facing is that I have to develop specific RE for each of the file which is very difficult when it comes to handle 1000s of files. can someone please tell me how to solve this problem. Change the files so that they all have the same format. Without knowing what the format is, how it differs from file to file, and what RE you use, what sort of answer did you expect? -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with regular expression
syed zaidi wrote: Dear Steve,Tutor doesn't allow attachment of huge files. I am attaching the files I am taking as input, code and the output CSV file. I hope then you would be able to help me. DOT keg files open in file viewer, you can also view them in python. The CSV file is the desired output file. There is no need to send four files when one will do. Also no need to send a file with multiple thousands of lines long when a dozen or so lines should be sufficient. It would also help if you told us what the fields in the file should be called. You are probably familiar with them, but we aren't. Since I don't know what the fields are called, I'm going to just make up some names. def parse_d_line(line): # Expects a line like this: # DSBG_0147 aceE; xxx xxx\tK00163 xxx xxx [EC:1.2.4.1] a, b = line.split('\t') # split on tab character c, d = a.split(';') letter, sbg_code, other_code = c.split() compound1 = d.strip() words = b.split() k_code = words[0] ec = words[-1] compound2 = .join(words[1:-1]) return (letter, sbg_code, other_code, compound1, k_code, compound2, ec) kegfile = open('something.keg') # skip lines until a bare exclamation mark for line in kegfile: if line.strip() == '!': break # analyse D lines only, skipping all others for line in kegfile: if line.startswith('D'): print(parse_d_line(dline)) elif line.strip() == '!': break # stop processing You will notice I don't use regular expressions in this. Some people, when confronted with a problem, think I know, I'll use regular expressions. Now they have two problems. -- Jamie Zawinski -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor