[Tutor] xlrd package
Hi, I want to know how many sheets can be created in Excel using xlrd package. Thank you ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Help needed
Hi, I need help with coding for the problem below. I am new in this area, so needed help. If anyone can help me program the below scenario, I will be thankful. I have this file: 1,3,5,0.03 2,3,5,5,4,0.11 3,3,5,5,4,5,8,0.04 2,5,8,7,8,0.04 3,14,10,14,13,17,13,0.04 1,14,18,0.06 4,10,13,14,13,17,13,12,13,0.04 4,11,6,11,9,11,12,11,19,0.08 3,19,20,15,20,21,20,0.24 1,21,20,0.05 3,20,21,21,16,21,22,0.27 And each line is interpreted as: - 1,3,5,0.03 -> This line means 1 link can be down i.e. between 3—5 with a probability of failure *0.03* - 2,3,5,5,4,0.11 -> This line means 2 links can be down i.e. between 3--5 and 5--4 with a probability of failure *0.11* (for each link) - 3,3,5,5,4,5,8,0.04 -> Similarly this line means 3 links can be down i.e. between 3--5 , 5—4 and 5—8 with a probability of failure *0.04*(for each link) - 2,5,8,7,8,0.04 -> This line means 2 links can be down i.e. between 5—8 and 7—8 with probability of failure *0.04* (for each link) - 3,14,10,14,13,17,13,0.04 -> Means 3 links can be down i.e. between 14—10, 14—13 and 17—13 with a probability of failure *0.04* (for each link) - 1,14,18,0.06 -> Means 1link can be down i.e. between 14—18 with a probability of failure as* 0.06* - 4,10,13,14,13,17,13,12,13,0.04 -> Means 4 links can go down i.e. between 10—13, 14—13, 17—13 and 12—13 with a probability of failure *0.04* (for each link) - 4,11,6,11,9,11,12,11,19,0.08 -> Means 4 links can go down i.e. between 11—6, 11—9, 11—12 and 11—19 with a probability of failure *0.08* (for each link) - 3,19,20,15,20,21,20,0.24 -> Means 3 links can go down i.e. between 19—20, 15—20 and 21—20 with a probability of failure *0.24* (for each link) - 1,21,20,0.05 -> Means 1 link is down i.e. between 21—20 with a probability of failure *0.05* - 3,20,21,21,16,21,22,0.27 -> Means 3 links are down i.e. between 20—21, 21—16 and 21—22 with a probability of failure as* 0.27* (for each link) I want to create two arrays using the above file (Links array and Prob array) that should give following output: *Links *= { [3,5] [5,4] [5,8] [7,8] [14,10] [14,13] [17,13] [14,18] [10,13] [14,13] [17,13] [12,13] [11,6] [11,9] [11,12] [11,19] [19,20] [15,20] [21,20] [20,21] [21,16] [21,22] } *Prob *= {[0.28] [0.15] [0.08] [0.04] [0.04] [0.04] [0.08] [0.04] [0.08] [0.08] [0.08] [0.08] [0.24] [0.24] [0.34] [0.27] [0.27]} *IMP Note*: The probabilities get added if a link is mentioned twice or thrice. For example: link 3—5 is repeated 3 times: in line one, it has a probability of failure as *0.03*, in line two it is *0.11* and in line three it is *0.04*. So the probability of failure for link 3—5 is 0.03+0.11+0.04 =* 0.28* So the first element in Links array is [3,5] and its probability of failure is the first element in Prob array i.e. 0.28 Can anyone help me with this please? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Opening a new script
From: Luky Romero >To: Alan Gauld >Sent: Saturday, 26 April 2014, 0:28 >Subject: Re: [Tutor] Opening a new script > > > >By script I mean the text editor that allows you to modify code, >and by shell, I mean the portion of the IDLE that allows you to >use the interpreter and the interactive part of Python simultaneously. No, you >cannot open a new file for editing from the IDLE shell. You have to use the File->New menu. But there are shortcuts (Ctrl-N on Linux) to do that from the keyboard if that helps. You can also import the file into the interpreter for testing but that can lead to problems if you change it and have to try to reload it. Personally I prefer to just run the file separately using Run Module (F5) and see the output in the shell window. HTH Alan G. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help With an Assignment
jordan smallwood Wrote in message: Do you know what a module is? Can you use a text editor to create one? Do you know what a function looks like? Try writing the first one they asked. Post it here, along with some test code showing it works, or describe what goes wrong. And while you're at it, switch your emails to plain text, and tell us at least what version of Python you're trying to use. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] trying to understand pattern matching code
rahmad akbar Wrote in message: > > to Dave, > i do i do the text mode? i had no idea this was on html Whatever mail program you're using is apparently defaulting to html. Find a menu item that specifies 'text' or 'plain text' or 'text only'. Or tell us what email program you're using, what os, and versions for each. Maybe someone will have experience with it. Back to your problem, do you understand what binary is, and how to convert (mentally) to and from decimal? Do you know that the bits have values of 1, 2, 4, 8, 16, etc? And that 24 is created by turning on the 16 bit and the 8 bit, commonly referred to as bits 4 and 3, respectively. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Learning
Leo Nardo Wrote in message: > I want to program. I enjoy programming and am willing to put in time > to do this.When I try to get started with programming I realize how > difficult it is to find the information worthy of learning. > I would like to write the > program in python, and I do not need a graphical interface. There is > something called a tibia api and I am not sure if its relevant. Tibia > is written in c++. Thanks :) I spent a while hunting through tibia.com, and saw no reference to the api. Perhaps it is only available to members, and I have no interest in joining. I think you need to go find the spec, perhaps starting by asking on the forum at tibia.com. I found a link that shows promise, but I see no indication that it is sponsored or even condoned by tibia.com (cipsoft). https://code.google.com/p/tibiaapi/ Also note that the changelog hasn't been updated for 4 years. Perhaps it doesn’t even work for more recent versions of tibia. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Difficulty in getting logged on to python.org; want to resubscribe at the beginner level; finding "While" Loops in Python 3.4.0 to be extremely picky
On 25/04/14 21:34, Stephen Mik wrote: Dear Sir(s): My name is Stephen W. Mik,my email address is "mik.step...@yahoo.com"; and I am having trouble logging on to the "Python Tutor Site". Do you mean the mailing list admin site? You seem to have succeeded because your email address is registered and this mail got through... I desperately need HELP with a Python 3.4.0 "Guess A Number" Homework Assignment 4 which is due VERY SOON.. That's fine we can offer help, we just don't do solutions. acknowledge,that I am a Python Programming amateur and some of my questions may seem trivial or naive Thats what this list is here for. computer is a 2007 MacIntosh which I can't configure to run Python 3.4.0. You should be able to get a version 3 Python running on it and there really isn't that much difference between Python 3.1 and 3.4. In fact even version 2 isn't so differnt you couldn't do useful wprk, you just need to translate it in the class lab that's all. Anyway,people,I need help with Python as soon as I can get it. You need to tell us what kind of help. The more specific the question the better the answer is likely to be. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Opening a new script
On 25/04/14 18:09, Luky Romero wrote: Is there a way to open a new file script using only the python shell? > I have both updated versions of python (2.7, 3.1) What do you mean by open a new file script? What do you mean by script? What do you mean by the python shell? There are several possible answers to each of those questions. We need specific details to help. What exactly are you hoping to do? -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Difficulty in getting logged on to python.org; want to resubscribe at the beginner level; finding "While" Loops in Python 3.4.0 to be extremely picky
You can get python 3.4 to work on your mac, but it has 2.5 or 2.4 which the OS uses and things can get very messed up if you don't know what you are doing. You should use virtualbox to run virtual OS's on your mac without messing up your main computer. You should probably describe what kind of error you are getting when trying to log in to the website. On Fri, Apr 25, 2014 at 4:34 PM, Stephen Mik < mik.step...@yahoo.com.dmarc.invalid> wrote: > Dear Sir(s): > My name is Stephen W. Mik,my email address is "mik.step...@yahoo.com"; > and I am having trouble logging on to the "Python Tutor Site". I > desperately need HELP with a Python 3.4.0 "Guess A Number" Homework > Assignment 4 which is due VERY SOON.. I recognize,and acknowledge,that I am > a Python Programming amateur and some of my questions may seem trivial or > naive;but a guy has to start somewhere.I was briefly on the mailing list > for a few days;unsubscribed Apr. 24,2014,and now I want to get back in,but > am having trouble doing so. I have to do my programming in a shared > computer lab(on Windows machines) Mondays,Tuesdays,Thursdays and limited > hours on Friday because my home computer is a 2007 MacIntosh which I can't > configure to run Python 3.4.0. Anyway,people,I need help with Python as > soon as I can get it.Thanks. > SINCERELY,Stephen W. Mik > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help With an Assignment
On 25/04/14 20:52, jordan smallwood wrote: Hello, I am new to Python. I mean completely new and we're working on this problem set where they give us specs and we have to build something based off these specs. I have no idea what they're asking. Its pretty clear. They want you to build a module containing two functions. Now how much of that do you not understand? Also do you know which version of python you are using - it can make a difference when you get to the details. And which operating system - less important for a task like this. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Difficulty in getting logged on to python.org; want to resubscribe at the beginner level; finding "While" Loops in Python 3.4.0 to be extremely picky
Dear Sir(s): My name is Stephen W. Mik,my email address is "mik.step...@yahoo.com"; and I am having trouble logging on to the "Python Tutor Site". I desperately need HELP with a Python 3.4.0 "Guess A Number" Homework Assignment 4 which is due VERY SOON.. I recognize,and acknowledge,that I am a Python Programming amateur and some of my questions may seem trivial or naive;but a guy has to start somewhere.I was briefly on the mailing list for a few days;unsubscribed Apr. 24,2014,and now I want to get back in,but am having trouble doing so. I have to do my programming in a shared computer lab(on Windows machines) Mondays,Tuesdays,Thursdays and limited hours on Friday because my home computer is a 2007 MacIntosh which I can't configure to run Python 3.4.0. Anyway,people,I need help with Python as soon as I can get it.Thanks. SINCERELY,Stephen W. Mik ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Help With an Assignment
Hello, I am new to Python. I mean completely new and we're working on this problem set where they give us specs and we have to build something based off these specs. I have no idea what they're asking. Could someone help get me started on the path to figuring this out? Below is the question: 1. Write a program module with at least two functions. Follow this specifi- cation exactly for these two functions: 1. (a) One function, CalculateCentimeters, receives a value in inches and returns the equivalent value in centimeters. centimeters =2.54×inches 2. (b) The other function, CalculateInches receives a value in centime- ters and returns the equivalent value in inches. inches =centimeters/2.54 ... but you don’t 2.54 in your code 2 times. It’s a good candidate to be a module-level constant. Specified instructions about the internals of code, i.e., the names of your functions and how they behave, is called the internal specification. It tells you, the author of the function, as well as programmers who call your function, how to call it and what to expect when it is called. You must following them exactly or call a meeting of your programming team because your choices here affect the others. For this exercise, you design the rest of the functions for your program, but be careful to keep all the code in functions. Invent and arrange functions as you wish to ask the user for: (a) a value (b) a unit of measure and call the appropriate function to print out the value in the other unit of measure. ©Marilyn Davis, 2007-2014 64 HOMEWORK Specified instructions about the user’s view of your code (like just given) is called the external specification. Often the paying customer gives these directions so you must follow them exactly, doing things in the order given; but in this case, the internal design is up to you. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Opening a new script
Is there a way to open a new file script using only the python shell? I have both updated versions of python (2.7, 3.1) -Luky ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Learning
On 25/04/14 12:00, Leo Nardo wrote: What i think would be helpful is an outline of all tactics and stuff I need to learn to complete a certain task that i am interested in. That's true provided the task is not too complicated to start with... This task is to write a very basic botting program for a pc game. That will only be possible if somebody on the list knows anything about this specific game. That's by no means certain. Tibia(Tibia.com). The program i want to write would start out being one simple feature. I want my program to look at my game and see when my health is below a certain ammount and heal my character by typing in a certain spell in the console of the game. Thats not necessarily simple. It involves interrogating another program and interacting with it. That may be quite easy if there is an exposed and documented programming interface but if not its quite an advanced programming task. Can anyone provide such a list of start to finish knowledge Unless you are lucky and find somebody here that knows this particular game then I doubt it. We focus on teaching the fundamentals of Python and its standard library. something called a tibia api and I am not sure if its relevant. > Tibia is written in c++. Thanks :) It depends a lot on what that interface looks like. There is no trivial way to connect Python to C++ code unless the interface has been designed to operate that way, which is unlikely. It may be possible but its not likely to be a simple job for a beginner. What is your experience level in programming? You say you enjoy it which implies you have some experience? What languages have you used other than python? -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Learning
I want to program. I enjoy programming and am willing to put in time to do this.When I try to get started with programming I realize how difficult it is to find the information worthy of learning. Programming is broad and the possibilities are endless, as well as the ammount of learning material. It is hard to find quality material that is understandable. What i think would be helpful is an outline of all tactics and stuff I need to learn to complete a certain task that i am interested in. This task is to write a very basic botting program for a pc game. Tons of people bot on this game and i would rather make my own program as opposed to using theirs. The game is called Tibia(Tibia.com). The program i want to write would start out being one simple feature. I want my program to look at my game and see when my health is below a certain ammount and heal my character by typing in a certain spell in the console of the game. After i can write this program from start to finish i believe i can work my way out to include other features and increase my programming skills. Can anyone provide such a list of start to finish knowledge that i could teach myself that would make this possible? I would like to write the program in python, and I do not need a graphical interface. There is something called a tibia api and I am not sure if its relevant. Tibia is written in c++. Thanks :) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] trying to understand pattern matching code
Thanks joel Could you elaborate more on bitwise, and why do we need to double bit. I experimented with some input ShiftAnd('pattern', 'textcontainingpatternandpatern') print out the (masks, accept_state), looks like bellow, the rest make sense couse the numbers are doubled, but the 't' goes 4+8 = 12. why is this? ({'a': 2, 'e': 16, 'n': 64, 'p': 1, 'r': 32, 't': 12}, 64) and i could not make sense of this line yet : D = (( D << 1) + 1) & masks [ c ] to Dave, i do i do the text mode? i had no idea this was on html Am 25.04.2014 14:16 schrieb "Joel Goldstick" : > > On Apr 25, 2014 7:14 AM, "rahmad akbar" wrote: > > > > hey guys, > > i am trying to understand this code pasted bellow, > > 1. what is line means? mask[c] |= bit > This bitwise or. It sets the rightmost bit in masks[c] > > 2. then the line bit *=2, this increment the bit to 2 for each characters > This doubles bit. > > 3. what is this line means? accept_state = bit //2 > Integer division > > 4. lastly, what is this scary line means? D = (( D << 1) + 1) & masks [ > c > > The << is bitwise shift left > > def ShiftAnd (P , T ): > > m = len ( P ) > > masks = dict () # empty dictionary > > bit = 1 > > for c in P : > > if c not in masks : masks [ c ] = 0 > > masks [ c ] |= bit > > bit *= 2 > > accept_state = bit // 2 > > D = 0 # bit - mask of active states > > i = 0 > > for c in T : > > D = (( D << 1) + 1) & masks [ c ] > > if ( D & accept_state ) != 0: > > yield i > > i += 1 > > > > > You should sprinkle some print statements in and run with various arguments > > > > > > > > -- > > many thanks > > mat > > > > ___ > > Tutor maillist - Tutor@python.org > > To unsubscribe or change subscription options: > > https://mail.python.org/mailman/listinfo/tutor > > > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] trying to understand pattern matching code
You both posted in html, rather than text mode. Joel Goldstick Wrote in message: > > > > 1. what is line means? mask[c] |= bit > This bitwise or. It sets the rightmost bit in masks[c] Only the first time through the loop, when bit == 1 -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] trying to understand pattern matching code
On Apr 25, 2014 7:14 AM, "rahmad akbar" wrote: > > hey guys, > i am trying to understand this code pasted bellow, > 1. what is line means? mask[c] |= bit This bitwise or. It sets the rightmost bit in masks[c] > 2. then the line bit *=2, this increment the bit to 2 for each characters This doubles bit. > 3. what is this line means? accept_state = bit //2 Integer division > 4. lastly, what is this scary line means? D = (( D << 1) + 1) & masks [ c The << is bitwise shift left > def ShiftAnd (P , T ): > m = len ( P ) > masks = dict () # empty dictionary > bit = 1 > for c in P : > if c not in masks : masks [ c ] = 0 > masks [ c ] |= bit > bit *= 2 > accept_state = bit // 2 > D = 0 # bit - mask of active states > i = 0 > for c in T : > D = (( D << 1) + 1) & masks [ c ] > if ( D & accept_state ) != 0: > yield i > i += 1 > > You should sprinkle some print statements in and run with various arguments > > > > -- > many thanks > mat > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] trying to understand pattern matching code
hey guys, i am trying to understand this code pasted bellow, 1. what is line means? mask[c] |= bit 2. then the line bit *=2, this increment the bit to 2 for each character? 3. what is this line means? accept_state = bit //2 4. lastly, what is this scary line means? D = (( D << 1) + 1) & masks [ c def ShiftAnd (P , T ): m = len ( P ) masks = dict () # empty dictionary bit = 1 for c in P : if c not in masks : masks [ c ] = 0 masks [ c ] |= bit bit *= 2 accept_state = bit // 2 D = 0 # bit - mask of active states i = 0 for c in T : D = (( D << 1) + 1) & masks [ c ] if ( D & accept_state ) != 0: yield i i += 1 -- many thanks mat ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Remove last newline only in print / open / read function
Chris Wrote in message: > Hi, > > I'm a Python Newbie. Probably, this is a simple question. But what is your context? Your Python version (apparently 2.x, since you're using print as a statement, rather than a function)? What os, and what is stdout pointing to, since you're pretending that you can write binary data to it? > > I've a function that offers a ZIP-file for download: > > def download_cert(form, config): >cn = form['cn'].value >serial = pki.util.serial_from_cn(config, cn) >files = pki.util.cert_files(config, cn, serial, True) >try: > name = path.join(tempfile.mkdtemp(), cn + '.zip') > zip = zipfile.ZipFile(name, 'w') > for file in files: > zip.write(file, path.basename(file)) > zip.close() (1) >except: > pki.cgi.start_html('Internal error', True) > pki.cgi.show_error(str(sys.exc_info()[1])) > pki.cgi.show_link('Go Back') > pki.cgi.end_html() >else: > print 'Content-Type: application/zip' > print 'Content-Disposition: attachment;filename=' + cn + '.zip' > print > print open(name).read() (2) print adds a newline. Use write () instead. sys.stdout.write (open (name).read ()) This assumes stdout is opened in binary mode, so that bytes that happen to look like a newline are not corrupted. > os.remove(name) > os.rmdir(path.dirname(name)) > > The ZIP file on the server is okay (1), but when it's sent to the client > (2), there's a linefeed in the last line. This makes the zip invalid. So > how can I remove the last linefeed only? > Minimum change is to add a comma at the end of the print statement. But I'd prefer write method, to be parallel with the read (). Do you know that memory is not a problem, since you're reading the entire temp file in before writing any of it to stdout? If you're not sure, replace this with a loop. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Remove last newline only in print / open / read function
On 24/04/14 20:09, Chris wrote: for file in files: zip.write(file, path.basename(file)) zip.close() (1) print open(name).read() (2) The ZIP file on the server is okay (1), but when it's sent to the client (2), there's a linefeed in the last line. This makes the zip invalid. So how can I remove the last linefeed only? Can I first ask what makes you think there is an extra linefeed at the end? Is it because of the print output? You do remember that print adds a newline? If you do print open(name).read(), # trailing comma suppresses newline Does it look OK? Or were already taking that into account? -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] some things work in IDLE but not a command prompt and vice versa
On 24/04/2014 10:41, Alan Gauld wrote: On 24/04/14 00:14, Martin wrote: If I run from a command prompt, however, I get C:\Users\Martin\Documents\College\python>python pickle.py You have called your file pickle.py. So when you try to import pickle the interpreter sees your file first and imports that not the library pickle. Never name your files the same as modules in the standard library, or at least not the same as something you import. pickle.dump(contents,file2,True) AttributeError: 'module' object has no attribute 'dump' I get the opposite problem with themsvcrt.getch() function. It works OK when run from a command prompt, but under IDLE it returns immediately without waiting for a key-press, with value b'\xff'. Is this just a feature of the IDLE? I'd never noticed that particular quirk before but you are correct. I get the same behaviour on win8.1 with Python 3.3. I also get the same behaviour using Pythonwin (which is generally a much better IDE if you are on Windows BTW!) I'm not sure why they behave differently to the command line but most IDEs have slight oddities like this. If in doubt use the command line version as your reference. HTH Many thanks for the advice about file names. I was having great fun (or Python was having fun with me) trying to run a very simple program with the file name dictionary.py but sanity returned when I renamed it dictionery.py --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Remove last newline only in print / open / read function
Hi, I'm a Python Newbie. Probably, this is a simple question. I've a function that offers a ZIP-file for download: def download_cert(form, config): cn = form['cn'].value serial = pki.util.serial_from_cn(config, cn) files = pki.util.cert_files(config, cn, serial, True) try: name = path.join(tempfile.mkdtemp(), cn + '.zip') zip = zipfile.ZipFile(name, 'w') for file in files: zip.write(file, path.basename(file)) zip.close() (1) except: pki.cgi.start_html('Internal error', True) pki.cgi.show_error(str(sys.exc_info()[1])) pki.cgi.show_link('Go Back') pki.cgi.end_html() else: print 'Content-Type: application/zip' print 'Content-Disposition: attachment;filename=' + cn + '.zip' print print open(name).read() (2) os.remove(name) os.rmdir(path.dirname(name)) The ZIP file on the server is okay (1), but when it's sent to the client (2), there's a linefeed in the last line. This makes the zip invalid. So how can I remove the last linefeed only? -- Chris ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor