Re: [Tutor] Stolen thread: Bottom folk vs. toppers was trouble using2to3.py
I'm afraid you guys are witty! Good on you. Rob, you're right - and Alan, you're right too. BRA-VO. On Wed, Nov 4, 2009 at 12:19 AM, Alan Gauld wrote: > "Robert Berman" wrote > > The war between bottom posters and top posters has been long, arduous, >> and most often incredibly silly. >> > > It has, I agree but there is a very real difference in that gratuitous top > posting does actually become unreadable if not done very carefully. > And it also encorages people to leave the whole previous thread in > place which is very naughty for those who pay for ther internet > access by the byte! (Or those whose mail server implements > space quotas!) > > But if a general comment is being made that does not need to refer > to specific quotations from the earlier rtext then I have no problem > with top posting. Provided all but a small context quote is left below. > But please don't send me 3 pages of text to just add two sentences > at the top!!! > > > I simply propose that the only requirement to communications here is >> that replies and questions be well formulated, courteous, and reasonably >> intelligent. >> > > Ah but there's the rub, what is "well formatted"? :-) > > > If there are going to be arguments pertaining to the posts, let them be >> over content and not placement. >> > > When you are trying to respond to hundreds of emails a day a > few top posted messages can cause severe headaches. Personally I > just ignore anything that has top posting that is hard to read, I don't > have > time to unscramble it nor to waste time asking the poster to desist. > If they post scrambled mail it doesn't get answered... > > So its not quite a case of the "color of the bikeshed" because this one > does make a very real difference to the usability of the medium and > to the success of the message in reaching its full audience. > > In most cases it doesn't hurt much but in longer threads it does. > So, please folks, be sensitive to your readers. > > Alan G. > > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > -- Regards, Lloyd ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] parameters vs arguments
Parameter is what used to give/call value in function. Argument is what used to give/call value in command line interface. Am I correct??... Binto -Original Message- From: tutor-bounces+binto=triplegate.net...@python.org [mailto:tutor-bounces+binto=triplegate.net...@python.org] On Behalf Of Alan Gauld Sent: Thursday, November 05, 2009 2:08 PM To: tutor@python.org Subject: Re: [Tutor] parameters vs arguments "Kristin Wilcox" wrote > I'm just starting to learn Python, and some of the vocabulary has me a > bit > confused. FWIW I take great care in my tutor to highlight and explain the terminology of programming in my tutor. I italicise new words and explain them on first use. So it might be useful taking a look there if you find areas of confusion. > I'm reading stuff from multiple sources, and it seems to me like the > words > "parameters" and "arguments" are used interchangeably. This is a confusing one and people often do get them mixed up. Basically a parameter is what you call the thing used in the function definition. An argument is whats used when you call the function. Thus, at invocation, the parameter takes on the value of the argument. This is confused futher by some text books using the term "formal argument" instead of parameter. When you see "formal argument" it does just mean a parameter. Fortunately this usage is rare nowadays. > When I define, say, function example like this... > def example(x,y): > > are x and y arguments? or parameters? parameters > And when I call the function and pass it values > > example(32,17) are those values arguments or parameters? I *thought* this > was called 'passing arguments'... arguments HTH -- Alan Gauld 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 maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Evaluating a string expression
[snip] > I would like to know how would I evaluate a string expression in python. > For example, if i say: a = "3*2" > I want to do something to evaluate the variable 'a' to give me 6. How > can I do this? [/snip] The eval() function can do this: eval("3*2") WARNING: Long winded security rant below... Be *very* careful what strings you pass to eval(). It is executing code! If you're doing this in a controlled environment it's not a problem. If this is part of a bigger program which is going to be used by other people, perhaps even online, this is a potentially *huge* security risk. You will either have to very carefully parse the users input to control what they can and cannot do, or better, strictly control what the kernel permits the process to do. This includes what hardware resources (memory/processor time) the process is allowed. This way, even if (when) the process is hijacked, the damage will be very limited. Such a feat is accomplished by having the program execute as a user who has very limited permissions. This is something best (only?) done on UNIX/Linux/BSD flavored systems. This could be done via a setuid binary, or a *carefully written* root process which immediately demotes its privilege level upon execution/spawning of children. (Such a model is employed by programs like apache's httpd server, where one process is root owned and does nothing but spawn lesser privileged processes to handle untrusted data.) If this is something you're interested in, the os module features functions like, 'setuid()', 'setgid()', and notably 'chroot()'. For further security yet, you might look into isolating a process from the rest of the system, as is the case with FreeBSD's jails. These are really big topics and in the end, it really depends on what 'untrusted source' constitutes, and your operating environment. Writing bulletproof code in regards to security is challenging. It is a very specialized topic worthy of further study. But in most situations executing code from an untrusted source is a *really* bad idea, even with precautions as those outlined in the example URL provided by one of the other responses. (http://effbot.org/zone/librarybook-core-eval.htm) Sorry for all the lecture. I'll shut up now. :p -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Retrieving information from a plain text file(WinXP/py2.6.2/Beginner)
Hello all, Thank you all for your help. I appreciate it alot. I have been trying to work with file IO alot recently and would like to improve my little program so that I no longer use a hard coded list, but a text file that I can edit easily. The text file is three lines long and looks exactly like this: Reminder1,2009_10_28 Reminder2,2009_11_01 Reminder3,2009_11_15 My program consists of the following code: #]--[import modules]--[ from time import strftime, mktime, localtime from WConio import textcolor #][ #]--[define functions]--[ def read_reminders(): print "\nReading text file into program: reminders.txt" text_file = open("reminders.txt","r") reminders = [line.strip().split("'") for line in text_file] text_file.close() print reminders # def get_computer_date(): #Get today's date from the computer todays_date = strftime("%Y_%m_%d") return todays_date # def color_print(strings): #Change the text color in the WinXP dos shell #The way to use: #color_print([("string",color number),\ #(str(variable),color number),(etc)]) for string in strings: textcolor(string[1]) print string[0], # def change_to_julian(reminder_date): #Receives the year, month, and day #in the form of a single string (2009_10_15) #and changes it into three different int #variables. Then take those three variables #and append six zeros and change into a #julian date. date = [] date = reminder_date.split("_") year = int(date[0]) month = int(date[1]) day = int(date[2]) timetuple = (year, month, day) + ( (0,) * 6 ) unixtime = mktime(timetuple) timetuple = localtime(unixtime) print days_left(timetuple[7]) # [7] is the number of julian-date field of #the unixtime tuple. return days_left(timetuple[7]) # def days_left(julian_date): #This function calculates the days left #until a reminder. If the days left are #greater than 0 it will print normally. #If it is -1 then it will print differently. #Also if it is greater than -1 it will print #yet again differently. days_until_reminder = julian_date - localtime().tm_yday if days_until_reminder > 0: color_print ([("There are",7),(str(days_until_reminder),4),("days left until this reminder.",7),("\n",7)]) elif days_until_reminder == -1: color_print ([("\tYou have missed this reminder by",4),(str(days_until_reminder*-1),4),("day!",4),("\n",7)]) color_print [(" ",4),("\n",7)]) else: color_print ([("\tYou have missed this reminder by",4),(str(days_until_reminder*-1),4),("days!",4),("\n",7)]) color_print [(" ",4),("\n",7)]) print # def compare_reminders(todays_date): #This function compares the reminders #to the computer date. #It has three different paths: # 1.Matches today's date # 2.The reminder date has already # passed by # 3.The reminder date is yet to # come. #After determining which it is it will #access the change_to_julian and #days_left functions. #reminders.sort() color_print ([(" [-]",4),("\n",7)]) index = 0 while index < len(reminders): if todays_date == reminders[index][1]: print color_print [(" ",4),("\n",7)]) print "Today's reminder is: ",reminders[index][0],"on",reminders[index][1] color_print ([("\t\tTake care of this reminder immediately",2),("\n",7)]) elif todays_date > reminders[index][1]: print print "Whoops, you missed the following reminder.",reminders[index][0],"on",reminders[index][1] change_to_julian(reminders[index][1]) else: print print "Your upcoming reminders are: ",reminders[index][0],"on",reminders[index][1] change_to_julian(reminders[index][1]) index = index + 1 color_print ([(" [-]",4),("\n",7)]) #][ #]---[Main Program]---[ read_reminders() print reminders compare_reminders(get_computer_date()) pause_it = raw_input("Press a key to end: ") #][ Could someone explain to me why my read_reminders function retrieves the information, but cannot process that information? When I try and run the program I get the following error message: Reading text file into program: reminders.txt [['Reminder1,2010_10_15'], ['Reminder2,2010_11_01'], ['Reminder3,2010_11_15']] Traceback (most recent call last): File "reminders.py", line 182, in
Re: [Tutor] Change a text string from a list and change it into an integer number.(WinXP/py2.6.2/Beginner)
Hello all, I was wondering if it was possible to split a string that is seperated by the "_" character and changing the text into an integer? My current code is as follows: date = "cyear_11_05" date2 = date.split("_") check_year = date2[0] if check_year == "cyear": year = localtime().tm_year else: year = int(date2[0]) print year So my goal here is for python to check at the value of "date". If the value of "date[0]" is cyear then I want it to get the current year from the computer. If the value of date[0] is a number then I want to just change it into an integer. Currently the above code does not work unless I change the "if" statement to say: "if check_year == "c". Did I do the slice incorrectly? I thought that when you take the first location (0) of a list then it would take the "cyear" in stead of just the "c". All input is appreciated. Thanks in advance, Katt ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] parameters vs arguments
I understand now… Thanks Binto From: ALAN GAULD [mailto:alan.ga...@btinternet.com] Sent: Friday, November 06, 2009 7:41 AM To: BINTO Subject: Re: [Tutor] parameters vs arguments > Parameter is what used to give/call value in function. > Argument is what used to give/call value in command line interface. > > Am I correct??... No. parameters are what you use when you create the function definition. For example def f(x): return 2*x x is the parameter. Now when I call f() I must pass in a value (or variable with a value). The thing I pass in when I call f() is the argument. f(2) 2 becomes the argument for this particular call to f. The parameter x of f takes on the value 2 during this particular invocation. z = 7 f(z) z is now the argument of f for this invocation. The parameter x takes on the value 7, which is the value of the argument, z x is always the parameter of f() but the argument can change each time you call f() HTH, Alan G. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Change a text string from a list and change it into an integer number.(WinXP/py2.6.2/Beginner)
On Thu, Nov 5, 2009 at 8:44 PM, Katt wrote: > > Currently the above code does not work unless I change the "if" statement > to say: > "if check_year == "c". > > Did I do the slice incorrectly? I thought that when you take the first > location (0) of a list then it would take the "cyear" in stead of just the > "c". > > It works correctly for me. Try modifying your code: date = "cyear_11_05" date2 = date.split("_") check_year = date2[0] print check_year what does that do for you? -Wayne ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Change a text string from a list and change it into an integer number.(WinXP/py2.6.2/Beginner)
What do you want to say exactly ? is 'cyear' an integer ? let's say date1 = "1984_11_05" Then of course you can change it to an integer using following list-comprehension, >>> date1 = "1984_11_05" >>> date1_list = [int(i) for i in date1.split("_")] >>> date1_list [1984, 11, 5] or alternatively, >>> date1_list_alternate=map(int,date1.split("_")) >>> date1_list_alternate [1984, 11, 5] also your code seems to work on my system. On Fri, Nov 6, 2009 at 8:14 AM, Katt wrote: > Hello all, > > I was wondering if it was possible to split a string that is seperated by > the "_" character and changing the text into an integer? > > My current code is as follows: > > date = "cyear_11_05" > date2 = date.split("_") > check_year = date2[0] > if check_year == "cyear": > year = localtime().tm_year > else: > year = int(date2[0]) > print year > > So my goal here is for python to check at the value of "date". If the > value of "date[0]" is cyear then I want it to get the current year from the > computer. If the value of date[0] is a number then I want to just change it > into an integer. > > Currently the above code does not work unless I change the "if" statement > to say: > "if check_year == "c". > > Did I do the slice incorrectly? I thought that when you take the first > location (0) of a list then it would take the "cyear" in stead of just the > "c". > > All input is appreciated. > > Thanks in advance, > > Katt > > ___ > 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] Change a text string from a list and change it into an integer number.(WinXP/py2.6.2/Beginner)
import time def katt(d): date0 = d.split("_")[0] if date0 == "cyear": return int(time.strftime("%Y")) else: return int(date0) print katt("cyear_11_05") print katt("1984_11_05") l0nwlf-Arena:l0nwlf$ python katt.py 2009 1984 http://codepad.org/RBjKmNcA Hope this helps ! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor