Re: [Tutor] Question about time.gmtime

2009-11-02 Thread Eduardo Vieira
On Tue, Sep 29, 2009 at 8:11 AM, Eduardo Vieira  wrote:
> Hello, I had a problem with a script yesterday that made me puzzled.
> My time zone is US Mountain Time. This script was running nice last
> week, but yesterday it reported the date of today instead
> So, yesterday at 5:20pm this line:
> hoje = time.strftime("%a, %b %d, %Y", time.gmtime())
>
> Gave me this: "Tue, Sep 29, 2009" instead of "Mon, Sep 28, 2009"
> What's going on?
> Minutes ago, while I was investigating this I had this output:
>
 time.gmtime()
> time.struct_time(tm_year=2009, tm_mon=9, tm_mday=29, tm_hour=14,
> tm_min=48, tm_sec=49, tm_wday=1, tm_yday=272, tm_isdst=0)
 time.localtime()
> time.struct_time(tm_year=2009, tm_mon=9, tm_mday=29, tm_hour=8,
> tm_min=50, tm_sec=28, tm_wday=1, tm_yday=272, tm_isdst=1)
>
> I see there are 6 hours difference, but I'm sure the script ran before 6pm
> Should I simply modify my code to use localtime, instead? Why did it
> happen only yesterday?
>
> I'm using Windows XP Professional, and my clock says it's Tuesday,
> Sept. 29, 2009 and 9:10 AM
>
> Regards,
>
> Eduardo
>

Some time ago I experienced that. And today again. I wonder if it's
not related to the fact that I did some system restore operations
today?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Can we unroll a loop?

2009-11-02 Thread Kent Johnson
On Mon, Nov 2, 2009 at 3:52 PM, Tino Dai  wrote:
> Hi Everybody,
>
>  I am wondering about a better approach to doing this:
>
>  for obj in groups:
>        rVs = rVs + Event.objects.get(group=obj)
>     rVs.sort()

Assuming rVs is a list and Event.objects.get(group=obj) is also a
list, you can use
rVs = sum((Event.objects.get(group=obj) for obj in groups), [])

Kent
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Can we unroll a loop?

2009-11-02 Thread Tino Dai
Hi Everybody,

 I am wondering about a better approach to doing this:

 for obj in groups:
   rVs = rVs + Event.objects.get(group=obj)
rVs.sort()

 Instead what I'm looking for is to have a construct that would expand
out to this:

rVs =  Event.objects.get(group=groups[0]) |
Event.objects.get(group=groups[1]) \
| ... | Event.objects.get(group=groups[n-1]) |
Event.objects.get(group=groups[n])

 I don't know if this is even possible. I have looked at the built in
map function as well as
some of the itertools functions, but nothing seems to fit the bill. Is this
even possible and
if so, how?

Thanks in advance!
-Tino
___
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)

2009-11-02 Thread Dave Angel
(Looks like maybe you hijacked another thread, instead of just creating 
a new message, with new topic, for the list)


Katt wrote:

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 f

Re: [Tutor] Retrieving information from a plain text file (WinXP/py2.6.2/Beginner)

2009-11-02 Thread Serdar Tumgoren
Hi Katt,

It appears you did not return the list of reminders that you extracted
in the "read_reminders" function, but simply printed them from inside
that function.

If you modify your code as below to store the list in a variable
called "reminders", you  should be able to access the list in your
global namespace.

> 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
 return reminders

Also, on a side note, you can greatly improve the readability of your
code by using the triple-quote style for multi-line docstrings inside
functions (rather than the hash comment marks). I tend to use hash
marks for one-line/inline comments, since they can really become an
eyesore (at least IMHO) when used too liberally.

Also, Python's whitespace and code formatting conventions can handle a
lot of the "documentation" for you. For instance,  module imports are
typically always performed at the top of a script, so it's reasonable
to expect that others reading your code will understand you're
importing some modules.

Much of this spelled out in PEP's 8 (style guide) and 257 (doc strings):

http://www.python.org/dev/peps/pep-0008/
http://www.python.org/dev/peps/pep-0257/

HTH!

Serdar
___
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)

2009-11-02 Thread vince spicer
On Sun, Nov 1, 2009 at 5:37 PM, Katt  wrote:

> 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 

Re: [Tutor] Retrieving information from a plain text file (WinXP/py2.6.2/Beginner)

2009-11-02 Thread Katt

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'], 
['Remi

Re: [Tutor] CSS Minification

2009-11-02 Thread Kent Johnson
On Mon, Nov 2, 2009 at 6:38 AM, Stephen Nelson-Smith  wrote:
> Is there a Python CSS and/or javascript minifier available?

cssutils can minify CSS:
http://cthedot.de/cssutils/

jsmin has been ported to Python:
http://www.crockford.com/javascript/jsmin.py.txt

Kent
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Can't find modules at command line

2009-11-02 Thread Christian Witts

Sam Stout wrote:

I'm using Python on Mac OS X.  I usually run IDLE and get this result:

IDLE 1.2  
>>> import gun

Bang!
>>> 


However, when I try this from Terminal:

Jacks-Mac:~ Sam$ python
ActivePython 2.5.0.0 (ActiveState Software Inc.) based on
Python 2.5 (r25:51908, Mar  9 2007, 17:40:37) 
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin

Type "help", "copyright", "credits" or "license" for more information.
>>> import gun
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named gun
>>> 

This file is at [/Users/sam/Documents/gun.py].  What should I do to 
make it visible to Python?




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
  
In the console when you start it up you appear to be in your home 
directory `~` but your script is in the Documents folder so you will 
need to add Documents to your path for eg.

from sys import path
path.append('/path/to/script/to/be/imported')
import gun

--
Kind Regards,
Christian Witts


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Can't find modules at command line

2009-11-02 Thread Sam Stout
I'm using Python on Mac OS X.  I usually run IDLE and get this result:

IDLE 1.2  
>>> import gun
Bang!
>>> 

However, when I try this from Terminal:

Jacks-Mac:~ Sam$ python
ActivePython 2.5.0.0 (ActiveState Software Inc.) based on
Python 2.5 (r25:51908, Mar  9 2007, 17:40:37) 
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import gun
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named gun
>>> 

This file is at [/Users/sam/Documents/gun.py].  What should I do to make it 
visible to Python?


  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] CSS Minification

2009-11-02 Thread Stephen Nelson-Smith
Is there a Python CSS and/or javascript minifier available?

I've got to convert some ant scripts to python, and ant has a minifier
plugin that I need to replicate.

Maybe Beautiful Soup can do this?

S.

-- 
Stephen Nelson-Smith
Technical Director
Atalanta Systems Ltd
www.atalanta-systems.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Adding Value to CSV

2009-11-02 Thread Dave Angel
(Please don't top-post on a newsgroup that has the convention of adding 
new content after quoted text.)


Paras K. wrote:

What I am trying to do is as I am writing the row to the CSV file, I want to
add the string base on a few other checks that I still need to write.

Ex.

readline = '"152.88.91.98","BitTorrent Client Activity","1","2009-09-23
15:40:33"\r\n'

At the end of this based on my checks I want to be able to write a string
like

Part of DHCP Pool or Part of VPN Pool

So the final line should be something like this written to the CSV file:

'"152.88.91.98","BitTorrent Client Activity","1","2009-09-23 15:40:33",
"Part of DHCP Pool"

Thanx in advance for the help.

On Sun, Nov 1, 2009 at 7:16 AM, Dave Angel  wrote:

  

Paras K. wrote:



I have some code that is going through a number of test.

When I have the line that has been read I need to add another value at the
end of it, or write the information into another csv file

Example of my code:

for line in fh.readlines():
   readline = line
   ipline = readline
   ip = ipline.split(' ')[0]
   split_ip = ip.split('.')
   if ((split_ip[0] == '"152')):
   ff.write(readline)
   totalcount +=1


I need to add another piece, how can I add another field at the end of
ff.write(readline)


Any assistance would be greatly appreciated. Thank You.



  

If your program is correct so far, then you could add it simply with:
   ff.write(readline + " " + newdata)

Although your message subject says CSV, it looks like you're breaking the
line up by spaces.  So if in fact each field is constrained not to have a
space within, and there is a single space between fields, then the above
will work.

If, on the other hand, you have to deal with fields that can contain the
delimiter, perhaps escaped or quoted, then things get much more complicated.

DaveA




  


Now that your input format is entirely different than what your code can 
parse, my answer would have to be different as well.  If you were still 
doing it by hand, then you'd need to use strip() to remove the trailing 
newline, then concatenate with a comma, some quotes, and another newline.


But you probably ought to be using the csv module, since you're likely 
to come up with some fields having embedded commas in them, and split() 
cannot handle that.


Once you've got a csv.reader() and a csv.writer(), all you're looking 
for is  mydata.append(newdata)  to add newdata field to the end of a 
record.  The reader reads into a list, and the write writes from a list.


DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Adding Value to CSV

2009-11-02 Thread Christian Witts

Paras K. wrote:
What I am trying to do is as I am writing the row to the CSV file, I 
want to add the string base on a few other checks that I still need to 
write.


Ex.

readline = '"152.88.91.98","BitTorrent Client 
Activity","1","2009-09-23 15:40:33"\r\n'


At the end of this based on my checks I want to be able to write a 
string like


Part of DHCP Pool or Part of VPN Pool

So the final line should be something like this written to the CSV file:

'"152.88.91.98","BitTorrent Client Activity","1","2009-09-23 
15:40:33", "Part of DHCP Pool"


Thanx in advance for the help.

On Sun, Nov 1, 2009 at 7:16 AM, Dave Angel > wrote:


Paras K. wrote:

I have some code that is going through a number of test.

When I have the line that has been read I need to add another
value at the
end of it, or write the information into another csv file

Example of my code:

for line in fh.readlines():
   readline = line
   ipline = readline
   ip = ipline.split(' ')[0]
   split_ip = ip.split('.')
   if ((split_ip[0] == '"152')):
   ff.write(readline)
   totalcount +=1


I need to add another piece, how can I add another field at
the end of
ff.write(readline)


Any assistance would be greatly appreciated. Thank You.

 


If your program is correct so far, then you could add it simply with:
   ff.write(readline + " " + newdata)

Although your message subject says CSV, it looks like you're
breaking the line up by spaces.  So if in fact each field is
constrained not to have a space within, and there is a single
space between fields, then the above will work.

If, on the other hand, you have to deal with fields that can
contain the delimiter, perhaps escaped or quoted, then things get
much more complicated.

DaveA




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
  
Use .strip() to remove the end-of-line characters and then add the 
string you want to the end of the line including end-of-line character.


--
Kind Regards,
Christian Witts


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Structure of my simulation / monte-carlo

2009-11-02 Thread spir
Le Sun, 01 Nov 2009 20:34:56 -0500,
Dave Angel  s'exprima ainsi:

> And from what you said earlier, you WILL need function objects, probably 
> as parameters to the Simulation constructor.  So each instance of 
> Simulation will be given several function objects to specify the 
> distribution functions for the parameters to be used when creating 
> Applicants and Institutions.

A note on "function objects" (because you --Vincent-- seem to regard this 
notion as impressive, but maybe I'm wrong).
In python, function objects are functions, no more; all functions (and methods) 
are objects. Simply, the fact that they are objects, indeed, is revealed in the 
cases where you bind them to a name like any other object.

to an ordinary variable:

if random_choice == GAUSS:
randomFunc = gaussRandom

or to a func parameter:

def produceDistribution(self, randomFunc, more_param):
...
random_results = randomFunc(more_param)
self.distrib = Distribution(results)# if you have type for distrib

This is not so often needed, but your case in the good one.

The feature is present in most high-level languages. But this has not been true 
for a long time, especially for mainstream languages of the "imperative" field 
(while it was more common, even required, for functional languages). So, this 
feature has kept a kind of special prestige and "functions are first-class 
objects" often comes early in a list of language features. But there is nothing 
exceptional in this for a language like python that basically treats data as 
objects, id est that accesses data through references.

Denis
--
la vita e estrany


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Adding Value to CSV

2009-11-02 Thread Paras K.
What I am trying to do is as I am writing the row to the CSV file, I want to
add the string base on a few other checks that I still need to write.

Ex.

readline = '"152.88.91.98","BitTorrent Client Activity","1","2009-09-23
15:40:33"\r\n'

At the end of this based on my checks I want to be able to write a string
like

Part of DHCP Pool or Part of VPN Pool

So the final line should be something like this written to the CSV file:

'"152.88.91.98","BitTorrent Client Activity","1","2009-09-23 15:40:33",
"Part of DHCP Pool"

Thanx in advance for the help.

On Sun, Nov 1, 2009 at 7:16 AM, Dave Angel  wrote:

> Paras K. wrote:
>
>> I have some code that is going through a number of test.
>>
>> When I have the line that has been read I need to add another value at the
>> end of it, or write the information into another csv file
>>
>> Example of my code:
>>
>> for line in fh.readlines():
>>readline = line
>>ipline = readline
>>ip = ipline.split(' ')[0]
>>split_ip = ip.split('.')
>>if ((split_ip[0] == '"152')):
>>ff.write(readline)
>>totalcount +=1
>>
>>
>> I need to add another piece, how can I add another field at the end of
>> ff.write(readline)
>>
>>
>> Any assistance would be greatly appreciated. Thank You.
>>
>>
>>
> If your program is correct so far, then you could add it simply with:
>ff.write(readline + " " + newdata)
>
> Although your message subject says CSV, it looks like you're breaking the
> line up by spaces.  So if in fact each field is constrained not to have a
> space within, and there is a single space between fields, then the above
> will work.
>
> If, on the other hand, you have to deal with fields that can contain the
> delimiter, perhaps escaped or quoted, then things get much more complicated.
>
> DaveA
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor