Re: [Tutor] OverflowError in lucky numbers script

2012-01-23 Thread Steven D'Aprano
On Mon, Jan 23, 2012 at 06:43:50PM +0530, Shreesh bhat wrote: > The program should check the islucky condition between range of (1,10**18) > numbers and iterate over that 10**5 times. How is the islucky condition defined? The only version I have found is based on something quite similar to prim

Re: [Tutor] OverflowError in lucky numbers script

2012-01-23 Thread Steven D'Aprano
On Mon, Jan 23, 2012 at 10:01:33PM +, Alan Gauld wrote: > Just to be clear this has nothing to do with Python. It doesn't matter > what programming language you choose there is not a PC on Earth that can > do what you want using the technique you are using in 16 seconds. I don't believe tha

Re: [Tutor] P4Python silent Installation

2012-01-25 Thread Steven D'Aprano
Nitish Mahajan wrote: I use Python 2.5 and hence consequently use the file P4Python-1.0.win32-py2.5.exe in order to add the Perforce APIs. I would like to create a silent installation for them. Hello Nitish, This mailing list is for people interested in learning the language Python, not for

Re: [Tutor] how to read and write to a file

2012-01-25 Thread Steven D'Aprano
Joel Goldstick wrote: First of all, always remember to reply to all on the list. That keeps everyone in the loop. Second, don't 'top post'. Write your comments at the end of the thread so that people can follow the conversation. Sometimes its useful to intersperse comments in someone's previo

Re: [Tutor] how to read and write to a file

2012-01-25 Thread Steven D'Aprano
Steven D'Aprano wrote: (And yes, I deliberately had one fewer answer than question in the second case. Top posting makes it MUCH easier to miss questions.) Gah! Brain fart! Please ignore the comment in parentheses. -- Steven ___ Tutor mai

Re: [Tutor] Pythonic way of concatenation of elements in an array

2012-01-26 Thread Steven D'Aprano
spa...@gmail.com wrote: Hello, My code is - l = len(m) item = str(m[1]) for i in range(2,l): item = item + "-" + str(m[i]) This code is part of a bigger function. It works fine. But I am not happy with the way I have written it. I think there is a better (Pythonic) way to rewrite it. If an

Re: [Tutor] Why do you have to close files?

2012-01-26 Thread Steven D'Aprano
amt wrote: I don't get it. If you don't close input and output it works exactly the same as if you would close them, so why do you have to do output.close() and input.close()? (1) It is a matter of good programming practice. If you don't close them yourself, Python will eventually close them

Re: [Tutor] compile time calculator

2012-01-27 Thread Steven D'Aprano
Surya K wrote: can anyone write a program for me? please... Certainly. My rate is AUD$80 per hour. Please write to me privately to discuss financial arrangements. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscr

Re: [Tutor] Socket Programming

2012-01-27 Thread Steven D'Aprano
Navneet wrote: One more thing I want to add here is, I am trying to create the GUI based chat server.(Attached the programs.) Please do not send large chunks of code like this, unless asked. Instead, you should try to produce a minimal example that demonstrates the problem. It should be:

Re: [Tutor] Rounding Error

2012-01-27 Thread Steven D'Aprano
Michael Lewis wrote: I am trying to round a float to two decimals, but I am getting the following error: Traceback (most recent call last): File "", line 1, in PaintingProject() File "C:/Python27/Homework/Labs/Lab 03_5.py", line 42, in PaintingProject print 'That will cost you $%f.'

Re: [Tutor] how to convert usec/pass to seconds

2012-01-28 Thread Steven D'Aprano
Surya K wrote: I am actually using a activestate wrapper for calculating execution time of my program. [...] I tested it for a puzzle and that showed me around 1385.33 usec/sec..However, as its from facebook hackers cup where I got a penalty time of 28.32.00 (not exactly, forgot).. what units

Re: [Tutor] How to split something?

2012-01-28 Thread Steven D'Aprano
Alan Ting wrote: Hello, How do I get the characters to separate? It isn't clear what you mean. Do you mean this? "JOON" => "J O O N" If so: ' '.join('JOON') will do it. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change

Re: [Tutor] How to split something?

2012-01-28 Thread Steven D'Aprano
Alan Ting wrote: Hello, How do I get the characters to separate? This is what I did. def personalNote(name): 'Print a personalized love note' x = (name) Oh, I forgot to mention... the line x = (name) is utterly pointless. Instead of wasting time with x=name, just use name everywhere yo

Re: [Tutor] Python with HTML

2012-01-29 Thread Steven D'Aprano
Evert Rol wrote: hi everyone, I want to make a web page which has to include some python script and html tags as well, am not getting how to do that . I searched some articles but cant understand them . is there anything like linking an external html file into python script ? Can u please hel

Re: [Tutor] Deleting an object

2012-01-29 Thread Steven D'Aprano
George Nyoro wrote: class Table: def delete_this(self): #code to delete this object or assign it null or None pass def do_something(self): pass x=Table() x.delete_this() #at this point, I want such that if I try to use x I get some sort of error e.g. x.do_something() #Error: x is definitely

Re: [Tutor] loop until a keypress

2012-01-30 Thread Steven D'Aprano
Surya K wrote: I am on windows. So, as msvcrt is for windows, I wonder if there is any module that works for both, http://code.activestate.com/recipes/577977 -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription opt

Re: [Tutor] Sort

2012-01-30 Thread Steven D'Aprano
George Nyoro wrote: Hey all, again: Thanks for the delete thing. Helped with that problem a lot. Especially the getattr thing came in handy. Question 1: How do you guys indent and put in the triple greater than signs and all that when sending mail? Manually? Coz the last mail I sent was using th

Re: [Tutor] trouble placing code into wxpython

2012-02-01 Thread Steven D'Aprano
On Wed, Feb 01, 2012 at 09:26:00PM -0500, Shane wrote: > Do I have to rewrite my code directly into wxpython frame > or can i just copy and paste it somehoe I don't know. If you try to copy and paste it, what happens? I'm afraid your question doesn't make much sense to me, and unless there happe

Re: [Tutor] Fwd: Re: trouble placing code into wxpython

2012-02-02 Thread Steven D'Aprano
shane wrote: i was trying to put the math.py into a frame Ive watched many tutorials. But cant seem to find out how to or where to place the code the files I want combined are attached. Do you mean you want to show the code in the GUI? You need to know the location of the file, then read the

Re: [Tutor] __getattribute__

2012-02-03 Thread Steven D'Aprano
Stayvoid wrote: Hi! Could you provide some examples (easy and hard ones) and comments on the topic? I'm trying to understand how this thing works. When you do an attribute lookup on an object, say obj.attr, Python uses something like a search path to find the attribute: it tries various thing

Re: [Tutor] __getattribute__

2012-02-03 Thread Steven D'Aprano
Alan Gauld wrote: On 04/02/12 00:30, Stayvoid wrote: Could you provide some examples (easy and hard ones) and comments on the topic? I'm trying to understand how this thing works. Commenting on the topic... It's not one most beginners(*) should be worrying about you rarely need to use it. B

Re: [Tutor] Importing libraries

2012-02-04 Thread Steven D'Aprano
Michael Lewis wrote: Why don't I have to import str or list to access their attributes like I do with the math or random or any other library? Because they are built-in. That means they live inside the Python compiler/interpreter itself. They are built-in because str, list, etc. are fundame

Re: [Tutor] SEE THE QUESTION AT THE BOTTOM

2012-02-04 Thread Steven D'Aprano
Debashish Saha wrote: INPUT: *for n in range(2, 1000):* *for x in range(2, n):* *if n % x == 0:* Please don't add junk characters to your code. There is no need to add asterisks to each line, we can recognise Python code when we see it. Your code cannot run because of the ju

Re: [Tutor] (no subject)

2012-02-04 Thread Steven D'Aprano
Debashish Saha wrote: [...] why did i get different values for the same input? Please choose a sensible subject line when posting. The problem is with the division. Watch: py> 21/2 10 py> 21.0/2 10.5 By default, division in Python 2 is integer division: any remainder is ignored. To use f

Re: [Tutor] factorial of anumber

2012-02-04 Thread Steven D'Aprano
Debashish Saha wrote: *PROGRAM TO FIND FACTORIAL OF A NUMBER(I HAVE WRITTEN IT ON GEDIT)* This program is irrelevant. Your question has nothing to do with factorial of numbers. It is about getting input from the user. As you ask: HOW TO ASK INPUT FROM USER THEN? The answer is: Do not use

Re: [Tutor] Return T/F vs print T/F

2012-02-04 Thread Steven D'Aprano
Sivaram Neelakantan wrote: While trying out code, I have trouble following the difference between return True vs print True and the same with False. If I use return for the True/False statements, nothing gets printed. Why? Probably because you aren't printing anything. Python can't read your

Re: [Tutor] Return T/F vs print T/F

2012-02-04 Thread Steven D'Aprano
Sivaram Neelakantan wrote: def palin(text): if first(text) == last(text): # print first(text), last(text), middle(text), len(middle(text)) if len(middle(text)) == 0: print True else: palin(middle(text)) else: print False Every br

Re: [Tutor] Sandbox Game

2012-02-05 Thread Steven D'Aprano
Nate Lastname wrote: Hey List, I am thinking about making a sandbox game. Where should I start? Has anyone done this before? I'm having trouble in MANY places, and This mailing list is for learning the Python programming language, not for answering arbitrary questions about anything vague

Re: [Tutor] Sandbox Game

2012-02-06 Thread Steven D'Aprano
On Mon, Feb 06, 2012 at 09:13:48AM -0500, Nate Lastname wrote: > Hello List, > > I am quite sorry for my attitude. I will look more thoroughly into the > search results. Thanks for the link to Epik. I had found this, but I > didn't realize that it was Python. I apologize once again, and thank

Re: [Tutor] Question on how to do exponents

2012-02-06 Thread Steven D'Aprano
On Mon, Feb 06, 2012 at 04:54:57PM -0800, William Stewart wrote: > Hello everyone, I am making a calculator and I need to know how to make it do > exponents and remainders > How can I input this info in python? > Any help would be appreciated You can do exponents either with the ** operator or th

Re: [Tutor] Class Nesting

2012-02-06 Thread Steven D'Aprano
On Mon, Feb 06, 2012 at 08:17:05PM -0500, Greg Nielsen wrote: [...] > So here is the problem, to create an object, you need to assign it to > a variable, and you need to know what that variable is to call upon it > later, so to have a object build a second object, it would need to somehow > cr

Re: [Tutor] Backwards message program

2012-02-07 Thread Steven D'Aprano
myles broomes wrote: Im trying to code a program where the user enters a message and it is returned backwards. Here is my code so far: message = input("Enter your message: ") backw = "" counter = len(message) while message != 0: backw += message[counter-1] counter -= 1 print(backw

Re: [Tutor] decimal precision in python

2012-02-07 Thread Steven D'Aprano
Steve Willoughby wrote: On 06-Feb-12 07:25, Kapil Shukla wrote: i tried writing a small code to calculate option price using the binomial tree model. I compared my results with results of the same program in excel. There seems to be a minor difference due to decimal precision as excel is using 1

Re: [Tutor] decimal precision in python

2012-02-07 Thread Steven D'Aprano
Col, I think you wrote to me personally by accident, instead of to the Tutor list. Nothing you said seems to be private, so I've taken the liberty of answering back on the list. col speed wrote: Just an idea - I'm not an expert by any means, just a dabbler, but: many years ago, when I was l

Re: [Tutor] Backspace Escape Sequence; \b

2012-02-07 Thread Steven D'Aprano
Peter Otten wrote: Garland W. Binns wrote: Could someone please tell me a common or semi-frequent scenario in which a person would use a backspace escape sequence? Does $ python -c 'print "this is b\bbo\bol\bld\bd"' | less qualify? If you are using (e. g.) Linux this technique is used to sh

Re: [Tutor] Question on how to do exponents

2012-02-07 Thread Steven D'Aprano
Sarma Tangirala wrote: Is is better to use pow() against **? Advantages of ** - it is shorter to type x**y vs pow(x, y) - being an operator, it is slightly faster than calling a function - you can't monkey-patch it Disadvantages of ** - being an operator, you can't directly use it as a fun

Re: [Tutor] general basic question

2012-02-08 Thread Steven D'Aprano
ken brockman wrote: Really close to it Robert. No delete but an error msg. Something akin to file dosen't exist, not found , or words to that effect . Something "akin to"? How about if you copy and paste the actual error message, instead of asking us to guess? That means the full traceba

Re: [Tutor] (no subject)

2012-02-09 Thread Steven D'Aprano
ken brockman wrote: I have been trying to post all afternoon to no avail. I keep getting bounced back... Ken, I don't suppose you have another email address that you sometimes use? Because if you do, that may be the problem. If you are subscribed to this list as krush1...@yahoo.com, and you

Re: [Tutor] What the difference between the two RE?

2012-02-09 Thread Steven D'Aprano
daedae11 wrote: import re re.match("^hello", "hello") re.match("hello", "hello") Please give a string that matches RE "^hello" but does not match RE "hello", or matches RE "hello" but does not match RE "^hello". re.match always matches the beginning of the string, so re.match("^hello", so

Re: [Tutor] How to make def where arguments are either stated when called or entered via raw_input

2012-02-09 Thread Steven D'Aprano
David Craig wrote: Hi, I'm trying to write a function that will either take arguments when the function is called, such as myFunc(x,y,z) or if the user does not enter any arguments, myFunc() the raw_input function will ask for them. But I dont know how to check how many arguments have been ent

Re: [Tutor] Ongoing problems with Pam's new computer

2012-02-09 Thread Steven D'Aprano
bob gailer wrote: Today is the third time Pam (connecting to the web site for event publication) has run into an inexplicable Access error. I don't think this has anything to do with learning Python. -- Steven ___ Tutor maillist - Tutor@python.or

Re: [Tutor] how to stop a running program in python without closing python interface?

2012-02-12 Thread Steven D'Aprano
Debashish Saha wrote: actually a i ran a progam in python which is sufficiently large . so i want to stop the execution of the program now . how can i do this? Control-C should work on every operating system. Obviously you have send the Ctrl-C to the Python process, not some other application.

Re: [Tutor] string integers?

2012-02-12 Thread Steven D'Aprano
William Stewart wrote: this is the code I have str1 = raw_input("Type in a String: ") str2 = raw_input("Type in a String: ") int1 = raw_input("Type in a integer variable: ") int2 = raw_input("Type in a integer variable: ") print str1 + str2 + int1 + int2 import math int1 = int(raw_input("")) p

Re: [Tutor] What's the difference between Queue(in module Queue) and list(build_in class)?

2012-02-13 Thread Steven D'Aprano
daedae11 wrote: What's the difference between Queue(in module Queue) and list(build_in class)? I think that when I pass a same queue object to two different threads, the change in each thread will affect each other as same as Queue. So why don't we use list or other variable object? Have you r

Re: [Tutor] ipython trouble with editor

2012-02-13 Thread Steven D'Aprano
David Craig wrote: Hi, I use emacs with ipython (or I would like to) on a GNU/linux machine. To be able to use it from the ipython shell through %ed I added the following lines to my .bashrc file, export LESS="-R" export EDITOR=emacs this seemed to work as when I try %ed filename it opens an

Re: [Tutor] problem in ploting cylinders with different colour.

2012-02-14 Thread Steven D'Aprano
Debashish Saha wrote: TypeError: grid_source() takes exactly 3 arguments (4 given) Is this error not clear enough? The function expects 3 arguments, you have given it 4. You need to give one fewer. The only tricky thing to remember is that when you have a method, one argument is the autom

[Tutor] Python in Java [was Re: Tutor Digest, Vol 96, Issue 69]

2012-02-16 Thread Steven D'Aprano
Nicholas Palmer wrote: I am fairly experienced in java and I was wondering how to use java in python code, if you could give me any tips.\ My first tip is to learn how to use email effectively. Doing so will increase the chances that volunteers on mailing lists will answer your questions with

Re: [Tutor] dict vs several variables?

2012-02-17 Thread Steven D'Aprano
Leam Hall wrote: I'm building a program that uses one of my own modules for a bunch of formula defs and another module for the tkinter GUI stuff. There are half a dozen input variables and about the same in calculated variables. Is it better/cleaner to just build a global dict and have everythi

Re: [Tutor] list comprehension efficiency

2012-02-18 Thread Steven D'Aprano
Bill Allen wrote: Generally speaking, are list comprehensions more efficient that the equivalent for loop with interior conditionals for a given task? Do they compile down to the same Python byte code? It depends, and no. For-loops are more general, so there are loops that can't be written as

Re: [Tutor] __name__=='__main__'

2012-02-20 Thread Steven D'Aprano
Michael Lewis wrote: Error I got when __name == ' __main__' was outside of any function: Traceback (most recent call last): File "C:/Python27/Homework/Homework5_1.py", line 24, in if __name == '__main__': NameError: name '__name' is not defined You have misspelled __name__ as __name.

Re: [Tutor] ssh from Windows to a Solaris server

2012-02-20 Thread Steven D'Aprano
Alan Gauld wrote: On 20/02/12 21:17, Do Nguyen (donguye) wrote: command1 = "plink -ssh -pw myPassword myUserName@myServerIP" p1 = subprocess.Popen(command1) p2 = subprocess.Popen('ls') I could verify that command1 was executed successfully, ie. the ssh to myServer worked, but command2 was trea

Re: [Tutor] Checking for file completion.

2012-02-21 Thread Steven D'Aprano
Tony Pelletier wrote: Missing a return statement in the case of an exception. Can you explain this? Why would I want the return on the exception? Because if you don't, it will return None. -- Steven ___ Tutor maillist - Tutor@python.org To un

Re: [Tutor] how to rewrite area.py

2012-02-21 Thread Steven D'Aprano
William Stewart wrote: hello I need to rewrite area.py program so that it has separate functions for the perimeter and area of a square, a rectangle, and a circle (3.14 * radius**2). I am horrible at math and I cannot even figure out what I need to do for this Any help would be appreciated Ha

Re: [Tutor] Pyhton editor

2012-02-21 Thread Steven D'Aprano
On Wed, Feb 22, 2012 at 01:01:50AM +, Alan Gauld wrote: > I seem to recall it was written in Borland's Delphi. > There is FreePascal which is very Delphi like, although not quite a > clone, it might be possible to port it to FreePascal if somebody was > keen enough! There is also GNU Pascal

Re: [Tutor] Recognizing real numbers

2012-02-21 Thread Steven D'Aprano
On Tue, Feb 21, 2012 at 07:00:40PM -0800, Michael Lewis wrote: > It seems that the .isdigit() function that I use doesn't recognize the .5 > as a number and therefore doesn't multiply it. How can I get my code to > recognize numbers such as .5, 1.75 as numbers? As the saying goes, it is often Eas

Re: [Tutor] Python assginment

2012-02-21 Thread Steven D'Aprano
On Wed, Feb 22, 2012 at 06:10:57AM +0530, Sukhpreet Sdhu wrote: > hi > i m working on Python assignment to convert roman numericals to arabic and > vice versa.I had tried many different codes but those are not working. > Can you please suggest me the code to do this by using while , if and else >

Re: [Tutor] Reading/dealing/matching with truly huge (ascii) files

2012-02-22 Thread Steven D'Aprano
On Wed, Feb 22, 2012 at 04:44:57PM +1100, Elaina Ann Hyde wrote: > So, Python question of the day: I have 2 files that I could normally just > read in with asciitable, The first file is a 12 column 8000 row table that > I have read in via asciitable and manipulated. The second file is > enormous,

Re: [Tutor] Create a table by writing to a text file.

2012-02-22 Thread Steven D'Aprano
David Craig wrote: I have been trying to write them to a text file but it is difficult to organise them into rows and columns with appropriate spacing to make it readable. I would like something like, Stations Station1 Station2 Station1 0.033.57654 Station2 33

Re: [Tutor] return integer from function

2012-02-22 Thread Steven D'Aprano
David Craig wrote: Hi, I have a function that calculates the distance between two points on a sphere. It works but I cant get it to return a float for use in another script. Anyone know how I do that?? You are going to have to explain what you mean in more detail. If you mean, how can you pa

Re: [Tutor] Compiled Python File

2012-02-22 Thread Steven D'Aprano
On Wed, Feb 22, 2012 at 07:29:42PM -0800, Michael Lewis wrote: > First, thanks to everyone who helped me out regarding my Recognizing real > numbers post. I gained a lot of knowledge over the past two days! > > I've noticed that after I execute some of my .py files, a Compiled Python > File is aut

Re: [Tutor] Which computer operating system is best for Python developers?

2012-02-22 Thread Steven D'Aprano
On Wed, Feb 22, 2012 at 07:00:57PM -0600, Tamar Osher wrote: > > Hi. I am still having trouble installing and using Python on my (new) > Windows 7 computer, but I plan to contact Microsoft forums and see if they > can help me, since this is a Windows problem and not a Python problem. > > My qu

Re: [Tutor] Solve wave equation

2012-02-23 Thread Steven D'Aprano
David Craig wrote: Hi, I am trying to write some code that will solve the 2D wave equation by the finite difference method, but it just returns an array full of zeros and NaN's. Not sure where I am going wrong, the code is attached so if could someone point me in the right direction I'd apprec

Re: [Tutor] Checking if a GtkEntry is empty

2012-02-24 Thread Steven D'Aprano
Anthony Papillion wrote: class Manager(object): def __init__(self): builder = gtk.Builder() builder.add_from_file("winMain.glade") builder.connect_signals(self) self.window = builder.get_object("winMain") self.window.show() conn = None

Re: [Tutor] Help with Python Program

2012-02-24 Thread Steven D'Aprano
Carolina Dianne LaCourse wrote: [...] I understand that I need to ask for raw input from the user and that I need to be able to use the if elif else to tell the user whether their number matches or id too high or to low but am just not sure what to do first. Any advice would be greatly appreciat

Re: [Tutor] Staticmethod & Classmethod Question

2012-02-25 Thread Steven D'Aprano
Chris Kavanagh wrote: I know this will sound stupid, but why would the method care which instance it's called on?? I think this is where my confusion is coming in. . .I hope I've made sense here. . . Typical use for class instances is to store per-instance information. For example, both "sp

Re: [Tutor] SOME KNOWLEDGE OF IRONPYTHON?

2012-02-26 Thread Steven D'Aprano
JOSEPH MARTIN MPALAKA wrote: Hullo to you All, Has any one used IronPython studio from microsoft Visual Studio. Am so new into IronPython please. It’s missing a help menu Tutorial link of "HOW TO" along the menu bar, so as to be used in learning and knowing how make out something. Could one be

Re: [Tutor] python questions about dictionary loops

2012-02-28 Thread Steven D'Aprano
justin fargus wrote: Hello, I'm new to Python. Just started a few weeks ago and I've been learning some basic things that I would like to put together but I don't even know where to began. I am trying to do the following: Make a program using two sentences of about 8 words (total between the t

Re: [Tutor] new to programming and wondering about an IDE for Python on Linux

2012-03-01 Thread Steven D'Aprano
On Mon, Feb 27, 2012 at 07:22:20AM -0800, John Jensen wrote: > Hi All, > > I'm new to programming and wondering about an IDE for Python on Linux. > I'd appreciate any feedback on this and good tutorials or books on > Python 3 and the IDEs suggested. There are many available and I'm > wondering

Re: [Tutor] python + sharepoint

2012-03-02 Thread Steven D'Aprano
Brad Hudson wrote: Can someone assist in a very basic task of retrieving a '.txt' file from a sharepoint document library using Python 2.4 standard libraries? What's a sharepoint document library? How would you retrieve a text file from it *without* using Python? [...] Note: url is changed

Re: [Tutor] python + sharepoint

2012-03-02 Thread Steven D'Aprano
Brad Hudson wrote: Still no response on this one, but I did find a 'rather ugly' solution using subprocess for wget to get a file from sharepoint... #!/usr/bin/env python import getpass import re import shlex from subprocess import Popen, PIPE # build sharepoint user/pw # note: shlex.split req

Re: [Tutor] mentorship

2012-03-02 Thread Steven D'Aprano
Christopher Conner wrote: I've got some free time and I feel like I should pick an open source project and begin contributing, but the options are just staggering. I've narrowed things down to the Python language - maybe the Plone project? maybe helping with documentation at first? Maybe testi

Re: [Tutor] Porting

2012-03-03 Thread Steven D'Aprano
On Sun, Mar 04, 2012 at 12:02:37PM +0530, Ejaj Hassan wrote: > Hello, > I am a novice in python development. I just came across this "Python > porting 2.7 to 3.x" . > I am just confused with this. Please tell me the whole meaning of it. Programmers talk about "porting" when they take code writt

Re: [Tutor] Blum blum shub pseudorandom generator

2012-03-05 Thread Steven D'Aprano
nivedita datta wrote: Hi, Can anyone send me a working code of BBS pseudorandom number generator. I'll do even better than send you working code for BBS -- I'll send you a link to how you can find working code for nearly ANYTHING! https://duckduckgo.com/html/?q=download+%22blum+blum+shub%22

Re: [Tutor] Question about writing to Excel with slavic characters

2012-03-05 Thread Steven D'Aprano
Marko Limbek wrote: Thank you! That was easy. Now I have another problem. I use RPy and read the spss database with method read.spss inside a nested R code in Python, that looks like that: import rpy r(""" library(foreign) baza <- read.spss(""" + analysis[0] + """) print(baza$demo_izob0) """)

Re: [Tutor] question about operator overloading

2012-03-05 Thread Steven D'Aprano
Alan Gauld wrote: On 05/03/12 21:25, Dave Angel wrote: It's not clear what __add__() should mean for physical files. My guess would be similar to the cat operator in Unix: $ cat file1, file2 > file3 is equivalent to file3 = file1 + file2 But of course, thats just my interpretation of file

Re: [Tutor] inserting new lines in long strings while printing

2012-03-06 Thread Steven D'Aprano
On Tue, Mar 06, 2012 at 05:26:26PM -0800, Abhishek Pratap wrote: > I have this one big string in python which I want to print to a file > inserting a new line after each 100 characters. Is there a slick way to do > this without looping over the string. I am pretty sure there shud be > something it

Re: [Tutor] Question about writing to Excel with slavic characters

2012-03-07 Thread Steven D'Aprano
Marko Limbek wrote: I put the recommended code savFileName = "C:/dropbox/Exc_MarkoL_Zenel/Valicon/crosstabs/Tabela/ipk108_kosovo_data_finale_c1-1.sav" with SavReader(savFileName) as sav: header = sav.next() for line in sav: process(line) but I am get errors Will you tell u

Re: [Tutor] Tuple - Immutable ?

2012-03-08 Thread Steven D'Aprano
Sudip Bhattacharya wrote: s=(1,2,3) s=s+(4,5,6) s (1,2,3,4,5,6) The tuple has changed. No it hasn't. You have created a *new* tuple, and assigned it to the same name. Consider: py> s = (1, 2, 3) py> id(s) 3083421332 py> t = s py> id(t) 3083421332 This shows that both s and t are names fo

Re: [Tutor] Tuple - Immutable ?

2012-03-08 Thread Steven D'Aprano
col speed wrote: I was just thinking about the immutability of things and tried this (which -at least I- find interesting: id(1) 154579120 a = 1 id(a) 154579120 a += 2 id(a) 154579096 id(3) 154579096 a is 3 True Although there is probably no other logical way of doing it - I learnt so

Re: [Tutor] Tuple - Immutable ?

2012-03-08 Thread Steven D'Aprano
col speed wrote: On 8 March 2012 18:51, Steven D'Aprano wrote: This makes sense, and is easy to understand. Now for the real boggle: py> a = 9912346; b = 9912346 py> a is b True Can you guess what is going on here? (Answer will follow later.) Because it's on the same li

Re: [Tutor] Refactoring

2012-03-08 Thread Steven D'Aprano
Ejaj Hassan wrote: Hi, I have been hearing this refactoring of code. Well does it have any thing like this in Python and if it is then what is it all about. "Refactoring" is a general technique that applies to any language, not just Python. Refactoring means to take a program which is writ

Re: [Tutor] Begginner

2012-03-08 Thread Steven D'Aprano
Bozra Moses wrote: Hi all, I have just finished installing python on a centos machine but I don't know where to begin learning this language. Do you know how to search the internet? You should always try searching the Internet first for an answer. https://duckduckgo.com/html/?q=python%20tut

Re: [Tutor] Python 3.2 - difference between out of dir() and help()

2012-03-08 Thread Steven D'Aprano
Flynn, Stephen (L & P - IT) wrote: All pretty standard stuff. I did however notice that the dir(x) told me about __class__, __reduce__ and __reduce_ex__ where the help(x) made no mention of them. Why is this difference? I presume the two commands using different means of getting

Re: [Tutor] Python using RXVT vs Konsole?

2012-03-08 Thread Steven D'Aprano
On Thu, Mar 08, 2012 at 09:07:46PM -0500, brandon w wrote: > I have noticed the difference in terminals when using the Python > interpreter. > I am able to up-arrow to get the last typed command using rxvt but when I > use konsole and I press the up-arrow I get the symbols: ^[[A > Why is that? Is t

Re: [Tutor] Floating point error in tkinter

2012-03-09 Thread Steven D'Aprano
On Fri, Mar 09, 2012 at 02:09:23PM +0100, Válas Péter wrote: > Hi, > > I use a tkinter-based editor that ran properly earlier on English Windows > XP. Now I use Hungarian Windows 7 with Python 2.7.2. You must know that in > Hungary decimal fractions are marked with a decimal comma, not a dot (e.g.

Re: [Tutor] UnicodeEncodeError: 'cp932' codec can't encode character '\xe9' in position

2012-03-11 Thread Steven D'Aprano
On Sat, Mar 10, 2012 at 08:03:18PM -0500, Dave Angel wrote: > There are just 256 possible characters in cp1252, and 256 in cp932. CP932 is also known as MS-KANJI or SHIFT-JIS (actually, one of many variants of SHIFT-JS). It is a multi-byte encoding, which means it has far more than 256 characte

Re: [Tutor] question on self

2012-03-11 Thread Steven D'Aprano
On Sun, Mar 11, 2012 at 07:02:11PM -0700, Michael Lewis wrote: > Why do I have to use "self.example" when calling a method inside a class? > > For example: > > def Play(self): > '''find scores, reports winners''' > self.scores = [] > for player in range(self.players):

Re: [Tutor] Finding a specific line in a body of text

2012-03-11 Thread Steven D'Aprano
On Mon, Mar 12, 2012 at 02:56:36AM +0100, Robert Sjoblom wrote: > In the file I'm parsing, I'm looking for specific lines. I don't know > the content of these lines but I do know the content that appears two > lines before. As such I thought that maybe I'd flag for a found line > and then flag the

Re: [Tutor] Finding a specific line in a body of text

2012-03-11 Thread Steven D'Aprano
On Mon, Mar 12, 2012 at 05:46:39AM +0100, Robert Sjoblom wrote: > > You haven't shown us the critical part: how are you getting the lines in > > the first place? > > Ah, yes -- > with open(address, "r", encoding="cp1252") as instream: > for line in instream: Seems reasonable. > > (Also, you

Re: [Tutor] more about how I overcame not being able to run my programs

2012-03-15 Thread Steven D'Aprano
Alan Gauld wrote: On 15/03/12 22:39, Tamar Osher wrote: try: import os # my program finally: input ('\n\t\t\tPress the enter key to continue.') os.system ('pause') It's more conventional to put the import at the very top, before the try: line. True, but in this case, if there is an import

Re: [Tutor] Datetime objects

2012-03-16 Thread Steven D'Aprano
Luke Thomas Mergner wrote: Hi, I am having trouble comparing two datetime objects. No you're not. You're having trouble comparing a datetime and a date object. [...] But when I compare them, it always returns false because datetime.date does not seem to compare to datetime.datetime... Use

Re: [Tutor] Permissions Error

2012-03-25 Thread Steven D'Aprano
Michael Lewis wrote: Hi everyone, If I've created a folder, why would I receive a permissions error when trying to copy the file. My source code is here: http://pastebin.com/1iX7pGDw The usual answer to "why would I receive a permissions error" is that you don't actually have permission to ac

Re: [Tutor] concurrent file reading using python

2012-03-26 Thread Steven D'Aprano
Abhishek Pratap wrote: Hi Guys I want to utilize the power of cores on my server and read big files (> 50Gb) simultaneously by seeking to N locations. Yes, you have many cores on the server. But how many hard drives is each file on? If all the files are on one disk, then you will *kill* perf

Re: [Tutor] Problem Stripping

2012-04-01 Thread Steven D'Aprano
leam hall wrote: Python 2.4.3 on Red Hat 5. Trying to use strip to remove characters but it doesn't seem to work like I thought. res = subprocess.Popen(['uname', '-a'], stdout=subprocess.PIPE) uname = res.stdout.read().strip() For future reference, you should identify the shortest possible am

Re: [Tutor] Problem Stripping

2012-04-02 Thread Steven D'Aprano
Please keep your reply on the list, unless you have something private to say. That way others can help, or learn from your questions. I've taken the liberty of putting this back into the list. Leam Hall wrote: On 04/01/2012 09:40 PM, Steven D'Aprano wrote: leam hall wrote: Pytho

Re: [Tutor] How is the return statement working in this function?

2012-04-05 Thread Steven D'Aprano
Greg Christian wrote: I am just wondering if anyone can explain how the return statement in this function is working (the code is from activestate.com)? Where does x come from – it is not initialized anywhere else and then just appears in the return statement. Any help would be appreciated. re

Re: [Tutor] Running scripts at login

2012-04-05 Thread Steven D'Aprano
Michael Lewis wrote: On 05/04/12 05:59, Michael Lewis wrote: Hi everyone, I am researching how to automatically run some of my scripts after I log into my Windows machine. I don't want to have to manually run the script or setup a windows task. The same way you run any Windows program on star

Re: [Tutor] How to have the name of a function inside the code of this function?

2012-04-06 Thread Steven D'Aprano
Karim wrote: Hello all, I have : def foo(): print( getattr(foo, 'func_name')) Why not this? def foo(): print 'foo' You already know the name of the function. There is no portable way of retrieving the name of the current function from within that function. -- Ste

Re: [Tutor] Is socket.socket() a func or a class

2012-04-06 Thread Steven D'Aprano
Khalid Al-Ghamdi wrote: hi all, I'm reading this book that says when creating a socket you have to use the socket.socket() *function *as in : ss=socket.socket() but whey i check they type it says it's a class which makes sense cause you're creating a socket object. type(ss) so, which is i

Re: [Tutor] which gets called

2012-04-06 Thread Steven D'Aprano
John Fabiani wrote: Hi, I want to create a class that inherits two other classes. class NewClass( A,B) But both "A" and "B" contain a method with the same name ("onKeyDown"). If my "NewClass" does not contain something to override the methods which one would be called if myinstance = NewC

<    8   9   10   11   12   13   14   15   16   17   >