Re: [Tutor] Printing from python
> is there another way to print a PDF form python? > > My problem is a PDF which is printed well by evince, but not with lp, > even not out of python using > > os.system("lp some_options file.pdf") > > Later on I have to build the PDF in a python program (using reportlab) > and then print it, even from the python program. I have done this several times before -- generating a pdf with python using reportlab and then printing the result by handing it to lpr. (Not sure what exactly is the difference between lp and lpr, but from a bit of research, it looks like either one should do the job.) The first thing you need to do is make sure that you can print the file from your regular shell (not python) using your chosen print command. If that does not work, python is not going to do anything magical. If you are having trouble with that, it is more of a question for the mailing list supporting your chosen operating system. Once you get that working, shelling out from python will be able to accomplish the same task. (The one possible gotcha is finding the correct path to the file. I think I tended to use full paths to everything to make sure that the correct things would be found.) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] please help
On 21/03/2014 21:39, Cameron Simpson wrote: On 21Mar2014 20:31, Mustafa Musameh wrote: I would collect the statistics using a dictionary to keep count of the characters. See the dict.setdefault method; it should be helpful. Delightfully old fashioned but I'd now prefer http://docs.python.org/3/library/collections.html#collections.Counter :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- 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
Re: [Tutor] please help
On Fri, Mar 21, 2014 at 08:31:07PM +1100, Mustafa Musameh wrote: > Please help. I have been search the internet to understand how to > write a simple program/script with python, and I did not do anything. > I have a file that look like this > >ID 1 > agtcgtacgt… > >ID 2 > acccttcc > . > . > . > in other words, it contains several IDs each one has a sequence of 'acgt' > letters > I need to write a script in python where the output will be, for example, > like this > > ID 1 > a = 10%, c = 40%, g=40%, t = 10% > >ID 2 > a = 15%, c = 35%, g=35%, t = 15% > . > . > . > (i mean the first line is the ID and the second line is the frequency of each > letter ) > How I can tell python to print the first line as it is and count > characters starting from the second line till the beginning of the > next '>' and so on This sounds like a homework exercise, and I have a policy of trying not to do homework for people. But I will show you the features you need. Firstly, explain what you would do if you were solving this problem in your head. Write out the steps in English (or the language of your choice). Don't worry about writing code yet, you're writing instructions for a human being at this stage. Those instructions might look like this: Open a file (which file?). Read two lines at a time. The first line will look like ">ID 42". Print that line unchanged. The second line will look line "gatacacagtatta...". Count how many "g", "a", "t", "c" letters there are, then print the results as percentages. Stop when there are no more lines to be read. Now that you know what needs to be done, you can start using Python for it. Start off by opening a file for reading: f = open("some file") There are lots of ways to read the file one line at a time. Here's one way: for line in f: print(line) But you want to read it *two* lines at a time. Here is one way: for first_line in f: second_line = next(f, '') print(first_line) print(second_line) Here's another way: first_line = None while first_line != '': first_line = f.readline() second_line = f.readline() Now that you have the lines, what do you do with them? Printing the first line is easy. How about the second? second_line = "gatacattgacaaccggaataccgagta" Now you need to do four things: - count the total number of characters, ignoring the newline at the end - count the number of g, a, t, c characters individually - work out the percentages of the total - print each character and its percentage Here is one way to count the total number of characters: count = 0 for c in second_line: count += 1 Can you think of a better way? Do you think that maybe Python has a built-in command to calculate the length of a string? Here is one way to count the number of 'g' characters: count_of_g = 0 for c in second_line: count_of_g += 1 (Does this look familiar?) Can you think of another way to count characters? Hint: strings have a count method: py> s = "fjejevffveejf" py> s.count("j") 3 Now you need to calculate the percentages. Do you know how to calculate the percentage of a total? Hint: you'll need to divide two numbers and multiply by 100. Finally, you need to print the results. Putting all these parts together should give you a solution. Good luck! Write as much code as you can, and come back with any specific questions you may have. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] please help
On 21Mar2014 20:31, Mustafa Musameh wrote: > Please help. I have been search the internet to understand how to write a > simple program/script with python, and I did not do anything. > I have a file that look like this > >ID 1 > agtcgtacgt… > >ID 2 > acccttcc > . > . > . > in other words, it contains several IDs each one has a sequence of 'acgt' > letters > I need to write a script in python where the output will be, for example, > like this > > ID 1 > a = 10%, c = 40%, g=40%, t = 10% > >ID 2 > a = 15%, c = 35%, g=35%, t = 15% > . > . > . > (i mean the first line is the ID and the second line is the frequency of each > letter ) > How I can tell python to print the first line as it is and count characters > starting from the second line till the beginning of the next '>' and so on You want a loop that reads lines in pairs. Example: while True: line1 = fp.readline() print line1, line2 = fp.readline() ... process the line and report ... Then to process the line, iterate over the line. Because a line is string, and a string is a sequence of characters, you can write: for c in line2: ... collect statistics about c ... ... print report ... I would collect the statistics using a dictionary to keep count of the characters. See the dict.setdefault method; it should be helpful. Cheers, -- Cameron Simpson ... in '59 I ran out of brakes *four times* -- and I don't mean they didn't work very well, I mean I had none. Like the main oil line had sheared. You know, so that oil, you know, when you put your foot on the floor, the oil just went squirting out into the atmosphere. Things like that. You know, I'd always believed that Colin was close to genius in his design ability and everything -- if he could just get over this failing of his of making things too bloody light. I mean, Colin's idea of a Grand Prix car was it should win the race and, as it crossed the finishing line, it should collapse in a heap of bits. If it didn't do that, it was built too strongly. - Innes Ireland ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fib sequence code assignment
On 21/03/14 21:21, Gary wrote: Got kinda close using temporary variable,but didn't know enough to use del. You don't really need to usae del, thats just being closer to what Python does - ie not leaving any temporary variables lying around. But in most programming languages you wouldn't bother deleting the temporary variable you'd just call it temp or somesuch. -- 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] Understanding code line
On Fri, Mar 21, 2014 at 01:14:22PM -0400, Gary wrote: > > Pythonists > > I am trying to understand the difference between > > a = b > b = a + b > and > > a,b = b, a+ b Try to evaluate the code in your head, as if you were the Python interpreter. Starting with the first version: a = b This assigns the value to b. So if b was 4, now a is also 4. b = a + b This takes the value of a and the value of b, adds them together, and assigns the result to b. Since the previous line set a to b, this is exactly the same as: b = b + b so if b was 4, it then becomes 8. The end result of these two lines is that b gets doubled each time. The important thing to realise here is that a gets its new value, the old value being lost, before it gets used to calculate b. Now for the second version: a, b = b, a+b Here, Python evaluates the right hand side of the = sign first, then does the assignments. On the RHS, it evaluates b, and a+b. Then it matches them with the names on the LHS, so that a gets the old value of b, and b gets the value of (a+b). The important thing here is that the values on the RHS are calculated before the assignments, so it works the way you expect. Most programming languages do not allow code like this, so you would have to use a temporary variable to get the same result: temp = a # remember the old value of a a = b # set the new value of a b = temp + b # set the new value of b -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Understanding code line
Gary writes: > Pythonists > > I am trying to understand the difference between > > a = b Retrieves the value referenced by ‘b’, then binds the name ‘a’ to the value. > b = a + b Evaluates the expression ‘a + b’, then binds the name ‘b’ to the result. > and > > a,b = b, a+ b Evaluates the expression ‘b, a + b’ – which will be a two-value tuple – then binds the names ‘a’ and ‘b’ to the two values from that tuple. Since the right side of the assignment, in each case, is evaluated before bindling the left side, the resulting values will depend on what the names are *currently* bound to at the time of evaluation. -- \“When in doubt tell the truth. It will confound your enemies | `\ and astound your friends.” —Mark Twain, _Following the Equator_ | _o__) | Ben Finney ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] please help
On 21/03/14 09:31, Mustafa Musameh wrote: Please help. I have been search the internet to understand how to write a > simple program/script with python, and I did not do anything. There are ma y tutorials on how to write Python for every level of programmer. What is your level? If you can already program then the official tutorial on the python.org web site is a good start. https://wiki.python.org/moin/BeginnersGuide/Programmers and http://docs.python.org/2/tutorial/ or http://docs.python.org/3/tutorial/ Depending on wheher you are using Pyton v2 or v3 - there are significant differences. If you cannot already program then this project will require quite a bit of work to learn the basics before you can start to solve your problem. For that you should look at the list of tutors for non programmers(including mine as cited below). https://wiki.python.org/moin/BeginnersGuide/NonProgrammers I have a file that look like this ID 1 agtcgtacgt… ID 2 acccttcc . This looks like bioscience? If so there are standard libraries available to help with processing that. Once you understand how to write basic Python you should probably download one of those libraries. There is a page for bioscientists using Python here: http://www.onlamp.com/pub/a/python/2002/10/17/biopython.html If you try one of the tutorials and have specific questions come back here and we can try to clarify things, -- 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] Fib sequence code assignment
Dear Jerry, Thank you so much, once you see it it seems so clear, but to see it I might as well be in the Indian Ocean. Got kinda close using temporary variable,but didn't know enough to use del. A lesson learn. Sent from my iPad ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] please help
On 21/03/2014 09:31, Mustafa Musameh wrote: Please help. I have been search the internet to understand how to write a simple program/script with python, and I did not do anything. I have a file that look like this ID 1 agtcgtacgt… ID 2 acccttcc . . . in other words, it contains several IDs each one has a sequence of 'acgt' letters I need to write a script in python where the output will be, for example, like this ID 1 a = 10%, c = 40%, g=40%, t = 10% ID 2 a = 15%, c = 35%, g=35%, t = 15% . . . (i mean the first line is the ID and the second line is the frequency of each letter ) How I can tell python to print the first line as it is and count characters starting from the second line till the beginning of the next '>' and so on Please help Welcome :) Start here http://docs.python.org/3/tutorial/index.html and then come back with specific questions about any problems that you may encounter. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- 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] please help
Please help. I have been search the internet to understand how to write a simple program/script with python, and I did not do anything. I have a file that look like this >ID 1 agtcgtacgt… >ID 2 acccttcc . . . in other words, it contains several IDs each one has a sequence of 'acgt' letters I need to write a script in python where the output will be, for example, like this > ID 1 a = 10%, c = 40%, g=40%, t = 10% >ID 2 a = 15%, c = 35%, g=35%, t = 15% . . . (i mean the first line is the ID and the second line is the frequency of each letter ) How I can tell python to print the first line as it is and count characters starting from the second line till the beginning of the next '>' and so on Please help ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tkinter and moving round button
On 21/03/14 03:31, cast fun wrote: I am trying to write a UI with text entry box for user input, buttons, and a moving circle when clicked popping up a new UI window. I was thinking Pygame, but didn't know how to show the text entry box. I am now using Tkinter, which is easy for the widgets, but the problem is the moving circle with the click event. While basic Tkinter usage is within our scope I suspect you may be better off pointing this one at the Tkinter mailing list (and maybe the pygame list too?) since it is very specific to Tkinter. 1. Can I use Sprite in Tkinter and if so how about the click event on the Sprite? 2. The other way I am thinking is in Tkinter, drawing a moving circle on the canvas, but don't know how to detect the click event to pop up a new window. The click event in a canvass is easily enough detected by binding to the mouse button events and reading the event information to find out where the mouse is and then determining whether it is within your circle (I seem to recall a shape method that tells you if a point is inside the boundary... but that might not have been in tkinter). 3. Or better in Tkinter if I can use a round button as the circle. I tried the image button. The rectangle border was always there, not really a round button. I don't know of any non rectangular widgets in Tkinter. The canvas might be the best option here. But I'd try the Tkinter mailing list. (If you cant find it, it is listed on the gmane.org news server as gmane.comp.python.tkinter) -- 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] Understanding code line
On 21/03/14 17:14, Gary wrote: Pythonists I am trying to understand the difference between a = b b = a + b This does exactly what it says. It first makes a and b identical then makes b equal their sum, that is, b+b and a,b = b, a+ b The second form is not always available in programming languages so R may not support it directly. The more general version would be: temp = a a = b b = temp + b Like to understand the second code sequence better so I can write the code in R and Scilab as well as python. HTH -- 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] (no subject)
On Fri, Mar 21, 2014 at 3:25 PM, Gary Engstrom wrote: > I am trying to understand function fibc code line a,b = b, a + b and would > like to see it written line by line > without combining multiply assignment. If possible. I sort of follow the > right to left evaluation of the other code. Sure. a,b = b, a+b is equivalent to: new_a = b new_b = a + b a = new_a b = new_b del new_a del new_b That is, we first evaluate everything on the right hand side of the equals sign, then assign those values to a and b. Then we get rid of the temporary variables, since the original statement didn't leave any temporary variable floating around. -- Jerry ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
Dear Pythonists Here is the code def fiba(n): a = 0 b = 1 while a < n : print(a) c = a + b a = a +c # 0,1,3,7,15,31,63 def fibc(n): a = 0 b = 1 while a < n : print(a) a, b = b,a + b #0,1,1,2,3,5,8,13,21,34,55,89 def fibb(n): a + b a = 0 b = 1 while a < n : print(a) a = b b = a+b #0,1,2,4,8,16,32,64 I am trying to understand function fibc code line a,b = b, a + b and would like to see it written line by line without combining multiply assignment. If possible. I sort of follow the right to left evaluation of the other code.___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Understanding code line
On Mar 21, 2014 1:16 PM, "Gary" wrote: > > > Pythonists > > I am trying to understand the difference between > > a = b You have overwitten a > b = a + b > and > > a,b = b, a+ b This one evaluates the right side first, then assigns the result to a and b > When used in my Fibonacci code the former generates 0,1,2,4,8,16,32 and the later > Generates 0,1,1,2,3,5,8,13,21,34,55,89. The second is the sequence I want, but I would > Like to understand the second code sequence better so I can write the code in R and Scilab as well as python. > G > > ___ > 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] Understanding code line
Pythonists I am trying to understand the difference between a = b b = a + b and a,b = b, a+ b When used in my Fibonacci code the former generates 0,1,2,4,8,16,32 and the later Generates 0,1,1,2,3,5,8,13,21,34,55,89. The second is the sequence I want, but I would Like to understand the second code sequence better so I can write the code in R and Scilab as well as python. G ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] mixing 64 bit and 32 bit
Depending on what you're doing you could run into problems. Areas that have been challenging for me in the past: * Loading 64bit compiled .dll in a 32bit Python environment and vice versa. * Reading registry entries. MS tried to be clever by introducing the Wow6432Node reg key. And I'm sure there has been a 3rd item that I am currently unable to recall. It involved py2exe. This might have been related to the registry issue mentioned above though. With all that said, if you know you're likely to have these kinds of issues it's pretty easy to write code that can deal with these types of problems and do one thing or another depending on the base OS. -- James On 19 March 2014 19:53, John Fabiani wrote: > Thanks > Johnf > > On 03/19/2014 11:01 AM, Reuben wrote: > > Hi John, > > The generated bytecodes will be different - but both version can run same > code without issues > > Regards, > Reuben > > On 19-Mar-2014 11:28 PM, "John Fabiani" wrote: >> >> Hi, >> >> At my office we have a mix of XP (32bit) and Window 7 (64 bit). I >> installed python 64 bit on the windows 7 machines and 32 bit on the XP >> machines. The question is can the different version run the same code >> without causing issues. Can the 64 bit use the same byte code as the 32 >> bit? It seems to be working but I thought best to check. >> >> Johnf >> ___ >> 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 maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Tkinter and moving round button
I am trying to write a UI with text entry box for user input, buttons, and a moving circle when clicked popping up a new UI window. I was thinking Pygame, but didn't know how to show the text entry box. I am now using Tkinter, which is easy for the widgets, but the problem is the moving circle with the click event. 1. Can I use Sprite in Tkinter and if so how about the click event on the Sprite? 2. The other way I am thinking is in Tkinter, drawing a moving circle on the canvas, but don't know how to detect the click event to pop up a new window. 3. Or better in Tkinter if I can use a round button as the circle. I tried the image button. The rectangle border was always there, not really a round button. Thanks you. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor