[Tutor] How to deploy Python 2.7, Django in OpenShift
I am really fed up with tutorials on web telling how to configure Django Python 2.7 on OpenShift DIY. So, can write a detailed step-by-step procedure on how to setup Django 1.4 with Python 2.7 on OpenShift using VirtualEnv?? Thanks a lot!!___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] A simple AJAX script needed
Here is what i need: I want to create a HTML button.. when clicked (should only work for once) should invoke a python script. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] How to authorize my application to use Google API
I am building a Facebook application using Django where I am using Blogger API. So, all I want is to just read the data from a public blog (my blog). I tried to read the documentation and found that we have 3 types of authentication mechanisms (ClientLogin, OAuth, AuthSub Proxy). As I can't directly put login credentials in the application (insecure), I have only one option to use. i.e., OAuth. The tricky part of my project is, the users(facebook users) should be able to access my data without providing any authorization information to Google. However, in the eyes of Google - OAuth, as I am pulling data from blog to display to public, I am considered as user who needs to authorize the application when ever someone opens the app on facebook, which is completely absurd... So, there might be two ways to do this: I should be able to pull data from blog without any authorization of user..How can I do it? If not I should be able authorize my application internally for OAuth so that facebook users can access data without providing any information to google.How can I do this?? If possible, is this a secure way? I am quite new to OAuth, Google API.. so, please suggest the best and secure way..___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] what would be the best authentication method for my facebook application
I am writing a facebook application in python where I used Blogger API to read posts from blogs (currently I am using ClientLogin under development). As each user(visitor) of my application should be able to view my without any authentication, I am using OAuth for authentication but I am unable to choose the type.. So, can anyone help in choosing what type of OAuth authentication I should use for my app and how could I do that.___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] How to read websites - Web Scraping or Parsing in python
Hi, I am trying to write a python program which reads any webpage's content. Considering a blog, I'd like to read all the content written by the author in it. So, each blog/ site would be having different type of HTML/ XML whether its Blogger or Wordpress or Typepad or any.. I thought of using their RSS/Atom feeds to extract the content. Then, I used Universal Feed Parser to extract the content. import feedparserurl = http://knolzone.com/feed; parsedFeed = feedparser.parse(url) websiteTitle = parsedFeed.feed.titlefor aArticle in parsedFeed.entries: print aArticle.link print aArticle.summary I could able to find links of all articles and their summaries with the website's title. But I'd like to read the whole content of a particular article, not just summary Say, for example we take a webpage http://knolzone.com/unlock-hidden-themes-in-windows-7-and-other-useful-tips-part-5-of-7/. The author had written some article in it and I'd like to read that portion of webpage. As my target webpage could be anyone of web, and each website's designers could have designed in their own fashion using different class names, I am unable to figure out how to read article content in a webpage. So, can anyone tell me what libraries should I ultimately use to achieve it ?? and what elements and attributes I should read?? I thought of using BeautifulSoup but I really don't know which elements ( div's or p or a ) I should read. Considering the above webpage given, I consists of lots of p elements in it and fortunately all the article content is in p elements.. However, there are few other p elements which don't belong to article content. In that case how should I eliminate them Thanks for reading.. I hope you help. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to deploy Django project in Google App Engine
Date: Sat, 26 May 2012 09:40:03 -0400 From: bgai...@gmail.com To: sur...@live.com CC: tutor@python.org Subject: Re: [Tutor] How to deploy Django project in Google App Engine On 5/26/2012 5:41 AM, Surya K wrote: I wrote a Django project and would like to deploy on Google App Engine. I searched a lot on net and couldn't find a proper tutorial till now. So, can any one explain me?? Did you look at http://www.allbuttonspressed.com/blog/django/2010/01/Native-Django-on-App-Engine? -- Bob Gailer 919-636-4239 Chapel Hill NC This seems to be a nice articles stating directly.. but I have one problem.1. In the test app, the project hierarchy is something like this:project folder/ project files - setting.py, __init__.py, manage.py, etc.. However, the Django's dir hierarchy in my PC (i.e, Django 1.4) is quite different.project folder/ folder , manage.py folder - __init__.py, settings.py, views.py etc... so, where should I store those folders mentioned in the website http://www.allbuttonspressed.com/blog/django/2010/01/Native-Django-on-App-Engine? Thanks Surya ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] How to deploy Django project in Google App Engine
I wrote a Django project and would like to deploy on Google App Engine. I searched a lot on net and couldn't find a proper tutorial till now. So, can any one explain me?? I used Eclipse Indigo, Python 2.7 for developing... ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] How to read blog posts in python
Hi, I want to write a python code which read blog's RSS/ Atom feeds and gives us the all post's content of blog... I am currently trying to use FeedParser (Universal Feed Parser). I am able to get all post's titles and URL's but not a content.. I tried to use certain functions mentioned in documentation but couldn't really understand how to do.. Can anyone help me how to do that? (I want to print the content exactly the way it has been written. I don't mind about fonts/ styles..) Thanks___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] How to start developing a website
I have a idea (Website) which I want to develop using Django (Still learning it!). Currently I am following DjangoBook (reading DataBase..). As I am really new to webframe works and Web development, I have a real dumb question which I don't really figure out. # Question: Broadly speaking my website takes a RSS/Atom feed and try to display dynamic content on its page. So, with what ever I know about django until now, all I can say that my project can handle creating dynamic content with django but I don't figure out how to really design it. I mean how to design the UI part.. .. One way of doing is to explicitly edit the Django's HTML pages using HTML, CSS, JavaScript from scratch. But I only know little HTML (I cannot do the design with what I know). So, how can I achieve this thing.. I thought of using Adobe's Dreamweaver or any equivalent open source thing but their generated HTML code can't be easily edited for django template designing.. Can anyone explain me on it.. Thanks a lot Surya ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] static methods class methods
I have a class, and want to use a method of it in the class itself. How can I do it? I mean, say I defined foo() , bar() methods in a class myClass. So, how can we i use foo() in bar(). I tried to use @staticmethod, @classmethod, but I am getting some errors.. sometimes saying unbound and sometimes given more than 1 parameters.. can any one tell me how to do this... I java it really works well. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] how to select a player to play first on a multiplayer game which runs on IRC
I am writing tic tac toe game which runs on IRC (i am using freenode now). Each player will be a channel member. So, players send private messages between each other to play game. This sounds fine but I need the below things to get done, but I don't know how to do them.. How my game works: Each player will have my program (tictactoe.exe). So, each player has to enter a unique Nick Name for them and a their's friend's nick name to play : ## Now, I want to know whether the player is on the channel or not. for that I need a list of nick's on the channel. How to get them? The biggest problem is here: ## How to select a player to play first... ??? How do I get this done? Help me!!!___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to select a player to play first on a multiplayer game which runs on IRC
Date: Thu, 19 Apr 2012 07:24:33 -0400 From: d...@davea.name To: sur...@live.com CC: tutor@python.org; bgai...@gmail.com Subject: Re: [Tutor] how to select a player to play first on a multiplayer game which runs on IRC On 04/19/2012 06:54 AM, Surya K wrote: I am writing tic tac toe game which runs on IRC (i am using freenode now). Each player will be a channel member. So, players send private messages between each other to play game. This sounds fine but I need the below things to get done, but I don't know how to do them.. How my game works: Each player will have my program (tictactoe.exe). So, each player has to enter a unique Nick Name for them and a their's friend's nick name to play : ## Now, I want to know whether the player is on the channel or not. for that I need a list of nick's on the channel. How to get them? I can't help there. The biggest problem is here: ## How to select a player to play first... ??? How do I get this done? In a peer-to-peer connection, there are a number of situations where you have to break symmetry. This is one of them, though not the first. Since you don't have a 3rd party arbiter, the two endpoints have to agree between themselves which of them is to be the arbiter when both sides need to agree on something. Once you've chosen the arbiter, then each decision is made by asking the arbiter. Start by choosing a large random number (or guid) at each end. Each sends his own guid along with the two nick-names to propose the new game. One of the guids will be larger, and that machine is the arbiter. The first conflict to be resolved this way is not who goes first, but how you make sure you only have one game between any two endpoints. What happens if more than two players are present, and what happens if more than one of them picks the same nickname? Are you going to permit one of the players to play against two others at the same time, and how will you keep the games straight? You need a connection token for each running game, and that's probably the first time you need an arbiter. Actually, as in a IRC channel, each user should have a unique nick name, the problem is resolved.Actually, in this game, the 2 players will have a private chat.. so, there would be no chance that other person will come into picture. Rather that doing all this mess, I want to put a server on Google App Engine and run clients on my PC. But I don't know how!! I have to know Google API for writing GAE app's using python 2.7 Lets say, I have created a server using python 2.7, can you tell me how to run it on GAE ?? (Assuming, I haven't used any google api).. Actually, I don't need any Templates, nice HTML pages on Google App. Its enough to just mention how many peers are connected at that particular instant... can you tell me how to do that?? The second case is choosing who goes first. The arbiter probably chooses that randomly, and notifies the other player. The third case is how to handle miscommunication. Messages can be lost between the end points, and you may have to reconstruct the state, so both ends get back in synch. Fourth is how to quit. If one player quits, the other might not get notified correctly, so you have to keep the connection token for a while, to aid cleanup. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] How to run a small python client-server on Google App Engine
I wrote a small python Client-Server program.. (I use python 2.7) and want to make it real. I mean, I want to put the server on Google App Engine.. I went through it and found that, I need to use Google API so that it should work on GAE. So, How could I create such a small Google App Engine's app. I mean.. Can anyone help me on it..(Assuming that there is a server.py which just shows how many clients are connected to it, how do I make a app of such program) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] How to interact with users on IRC using Python
Actually, I am writing a small IRC bot for a game (A Multiplayer one). This how my code looks. (I this code, I am just trying to read from IRC client and send a message to it..) import sysimport socketimport string HOST=irc.freenode.netPORT=6667NICK=MyBotIDENT=MybotREALNAME=Pythonreadbuffer= s=socket.socket( )s.connect((HOST, PORT))s.send(NICK %s\r\n % NICK)s.send(USER %s %s bla :%s\r\n % (IDENT, HOST, REALNAME))s.send(JOIN ##MyChannel\n) while 1:readbuffer=readbuffer+s.recv(1024)print readbuffer s.send(text:) # MY Code goes like this. Actually, I am not even aware of IRC commands.. so I thought to take some help to carry on This is what I require: As my game is quite simple, I just need to transfer a small string from each player to another. My game will have a two players.. so, Each user will join my ##myExampleChannel.Say, a player (or a IRC user) p1 wants to play with p2. They simply have to exchange private messages from each other. So, what IRC commands should I use and how do I typically implement them? Let me put the above this way: How do I create a small IRC program which can send and receive private messages from users? Thanks for reading! Hope you help me. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] should we use multithreading for multiple clients in socket class
I am learning networking and just wrote a primitive client server program.. server: from time import ctimefrom socket import * HOST = PORT = 21567BUFSIZ = 1024ADDR = (HOST, PORT) tcpSerSoc = socket(AF_INET, SOCK_STREAM)tcpSerSoc.bind(ADDR)tcpSerSoc.listen(5) while True:print waiting for connection..tcpCliSoc, addr = tcpSerSoc.accept()print # Connected from:, addrwhile True: data = tcpCliSoc.recv(BUFSIZ)if not data:break tcpCliSoc.send( [%s] %s % (ctime(), data )) tcpCliSoc.clock()tcpSerSoc.close() Client: from socket import * HOST = 'localhost'PORT = 21567BUFSIZ = 1024ADDR = (HOST, PORT) tcpCliSoc = socket(AF_INET, SOCK_STREAM)tcpCliSoc.connect(ADDR) while True:data = raw_input()if not data:break tcpCliSoc.send(data)data = tcpCliSoc.recv(BUFSIZ)if not data: breakprint datatcpCliSoc.close() This client sends a string, and receives the same string with current time... So, I tried to run another client (same code but from different file) but found that its now working. why its happening, should I use multithreading so that I can handle two clients simultaneously?? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] how to build a multiplayer game?
I have written the basic part of the game. Now I want to make it a multiplayer one. (Its not a web app, a OS application) So, I just wanted to know how do it. Which topics I should refer? Network Programming or Web Programming or Internet Client Programming. (There were the topics mentioned in Core Python Programming book). Can anyone tell me how do we achieve such a application (I mean without having a web server). I am not really ready to setup a Apache HTTP server. and all. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to build a multiplayer game?
Date: Wed, 11 Apr 2012 06:42:40 -0400 From: d...@davea.name To: sur...@live.com CC: tutor@python.org Subject: Re: [Tutor] how to build a multiplayer game? On 04/11/2012 06:02 AM, Surya K wrote: I have written the basic part of the game. Now I want to make it a multiplayer one. (Its not a web app, a OS application) So, I just wanted to know how do it. Which topics I should refer? Network Programming or Web Programming or Internet Client Programming. (There were the topics mentioned in Core Python Programming book). Can anyone tell me how do we achieve such a application (I mean without having a web server). I am not really ready to setup a Apache HTTP server. and all. You want to make two instances of the app talk to each other. If they're on the same machine (unlikely for a real game, but might be used for testing), or if they're on the same local network, then the features you need are available in the stdlib. If you're going out on the web, you need a host out there which will cooperate with the two apps (players). Same local network: Generally when both machines share a router or a wifi connection, and would get to the web through the same ISP connection. If you figure out what their IP addresses are, they can talk directly, using sockets. Well, can we make the program so that user enters his IP, DNS addresses before starting? Don't you think DNS is required as IP addr may be same for some people in this world.. after all, we only have limited number of combinations. (xx.xx.xx.xx .. ) * I even got a wild idea, can't we use a IRC channel, create a group and we make sure that each user of the game will be a member of the group??approx, how much delay would be there?? Out on the web: You need a server that's on the web that each machine can reach. It doesn't have to be your own, and I can't recommend any particular one, but I'd bet google appserver would work. For that matter, email would work, if you don't mind a pretty long delay between turns. Hmm, google app engine is a nice option but thing is I don't know how to use it. For any more specific advice, somebody else had better pop in. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] GUI for python Google App Engine
Hi there, I just wrote a small game in python and would like to make it a facebook app. These are the things I wish to know: 1. How to write GUI for my app. I believe, PyQt or Wx wouldn't work in Google App Engine.2. How to integrate my app with facebook. I went through facebook documentation but couldn't get it clearly.. this is what I require as per the game: Two players join a game and each player inputs a character.. Any small tutorials that would teach me would be appreciated.. Right now I don't want to learn about GAE or Facebook API in detail. I just want to build my app. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Unable to open .py files directly
Date: Mon, 19 Mar 2012 19:11:18 -0400 From: bgai...@gmail.com To: sur...@live.com CC: tutor@python.org Subject: Re: [Tutor] Unable to open .py files directly On 3/19/2012 10:30 AM, Surya K wrote: Hi there, I am facing a typical problem in opening .py files by clicking them (In windows). In addition to the other advice - open is ambiguous. What do you want to happen? Edit or execute? clicking a file usually just selects it. Do you mean double-click or what? The more precise you are regarding what you want and what you do makes it a lot easier for us to help. -- Bob Gailer 919-636-4239 Chapel Hill NC I was double clicking.. and I want to open IDLE. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Unable to open .py files directly
Date: Wed, 21 Mar 2012 13:29:17 + Subject: Re: [Tutor] Unable to open .py files directly From: bod...@googlemail.com To: sur...@live.com CC: tutor@python.org; bgai...@gmail.com On Mar 21, 2012 1:03 PM, Surya K sur...@live.com wrote: Date: Mon, 19 Mar 2012 19:11:18 -0400 From: bgai...@gmail.com To: sur...@live.com CC: tutor@python.org Subject: Re: [Tutor] Unable to open .py files directly On 3/19/2012 10:30 AM, Surya K wrote: Hi there, I am facing a typical problem in opening .py files by clicking them (In windows). In addition to the other advice - open is ambiguous. What do you want to happen? Edit or execute? clicking a file usually just selects it. Do you mean double-click or what? The more precise you are regarding what you want and what you do makes it a lot easier for us to help. -- Bob Gailer 919-636-4239 Chapel Hill NC I was double clicking.. and I want to open IDLE. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor In that case, you need to change the file association of .py files to IDLE Bodsda Yeah, I tried that. The worst part is we don't have any exe file specifically for IDLE. I mean windows has to choose whether to edit or compile. In my case, the file associated with my .py files is python.exe (c:/python27/python.exe). I still don't understand why its not opening in IDLE. If I am wrong, is there any special application (exe file) for IDLE so that I can configure to?? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Unable to open .py files directly
Hi there, I am facing a typical problem in opening .py files by clicking them (In windows). When ever I those files, there's a black window opening and closing immediately (I think, its output of python at python command line, NOT SURE). I have to open those files from IDE's or any test editors. I tried to fix it in 'default programs' list, but I just didn't find any problem there.. I use PyScripter IDE. I think, this is making trouble (don't know how). actually, this problem has occurred after installing it.(I use Win7) How do I fix it. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] New project idea!!
Hi, I am an electronics guy, extremely interested in programming. So learned Python. Currently I know (C, Python, HTML); Learning Java, Python (still making myself flexible in OOP). So, last year I build a sudoku solver in C which was an amazing experience (though re inventing wheel is not a big deal at all), I learned a lot. Now, I would like to do a similar project using python (which should be quite acceptable to put on my resume).. Any Ideas please!! (Note: I am no computer science guy, My day-to-day affairs deal with resistors, capacitors, transistors etc. I try to learn programming myself at home.. So, I wouldn't have knowledge exactly how a computer science guys will have. But I have more than enough enthusiasm..___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] New project idea!!
Subject: Re: [Tutor] New project idea!! From: las...@antalconsulting.com Date: Tue, 6 Mar 2012 09:24:12 -0800 CC: tutor@python.org To: sur...@live.com Hi, Since you are an electronics guy, how about a circuit simulator?You can start very simple with a power source and a light and show how the current flows.Add resistors and other bodies later. You could use pygame for the drawing and animation.I have been thinking of a simple app like that lately but I am don't have any former background in electronics and the know how, but I think it would be a great teaching tool and fun project. lzantal Well, that's not bad but I wish it should be something interesting... Actually, I have an idea to develop a multiplayer game (where friends connect across internet.. ) The problem is that, I don't know network/ socket programming. which itself takes a lot of time to learn.. : ( ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] loop until a keypress
I want to run code until a enter is pressed. Well, it shouldn't wait for the user to enter enter This is my code: import msvcrtchr = 0while chr != 'q': print my code, if msvcrt.kbhit(): chr = msvcrt.getch() This isn't working the way I wanted. When ever I press enter, the loop is starting in a new line and continuing. I even added break statement in if block but it isn't workingCan you tell me how to do that? I am on windows. So, as msvcrt is for windows, I wonder if there is any module that works for both, ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] compile time calculator
Date: Fri, 27 Jan 2012 17:35:39 -0800 Subject: Re: [Tutor] compile time calculator From: marc.tompk...@gmail.com To: sur...@live.com CC: tutor@python.org On Fri, Jan 27, 2012 at 7:46 AM, Surya K sur...@live.com wrote: Hi, I want to calculate compile time for my puzzles. Since nobody else has mentioned it yet... http://xkcd.com/303/ Well, using python documentation, I did this.. (calculating execution time). def main():## This is my whole puzzle code... fobj_ip = open('D:/code/py/input.txt', 'r')fobj_op = open('D:/code/py/output.txt','w') line=1for eachLine in fobj_ip:if line1: fobj_op.write (Case #%d: %d\n %(line-1, the_count(eachLine) ) )line+=1 pass if __name__ == '__main__':from timeit import Timermain()t = Timer(main())print t.timeit() This is showing the following output 1000 loops, best of 3: 0.0612 usec per loop (This is repeating...) So, what exactly is 0.0612 usec per loop, is that execution time of my whole program??If, how do I calculate it in seconds. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] how to convert usec/pass to seconds
I am actually using a activestate wrapper for calculating execution time of my program. This is the code #!/usr/bin/python# A simple wrapper for the timeit module.import timeit def Timeit(func,number=1,module=__main__): A wrapper which can be used to time any function name = func.__name__t = timeit.Timer(%s()%name, from %s import %s % (module, name))return %.2f usec/pass % (100*t.timeit(number=number)/number) if __name__==__main__: from program import* # Using wrapperprint Timeit(main)# Directly using timeitt = timeit.Timer(main(), from __main__ import main)print %.2f usec/pass % (100*t.timeit(number=1)/1) So, this module is showing my execution time in usec/pass. 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 facebook was following.. If I had to change those usec/pass units to seconds, what I have to use. can anyone tell me? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] compile time calculator
Hi, I want to calculate compile time for my puzzles. Although I read about timeit(), I didn't really understand how it should be applied it.So, can anyone write a function for me please!! I am looking for a function which should solve my puzzle and also show compile time. (Later, I should be able to delete that function before submitting my code) The following way is what I am exactly looking at: define a compile time function such that it should take all my puzzle code and provide compile time for it. (I think timeit() should be called at each statement, which is not flexible, don't know exactly.) can anyone write a program for me? please... ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to handle very large numbers
Date: Sun, 22 Jan 2012 21:28:14 -0500 From: d...@davea.name To: sur...@live.com CC: tutor@python.org Subject: Re: [Tutor] how to handle very large numbers On 01/22/2012 09:08 PM, Surya K wrote: Well, I have been doing a puzzle where I have to deal with number 10^18. A variable can store that value but can't do operations.Ex: If I use range() on it, it shows overflow error. So, How do I handle this. I have to use range() for that number.. in this instance. Also mention how to handle in other cases too (A small tutorial/ book would be appreciated ) Thanks Check out the ongoing thread of someone who's probably doing the same assignment. Subject is OverflowError in lucky numbers script Short answers for range(): You need to specify your Python version. In Python 2.7, range() has no problem handling longs as its arguments. It does have a problem when the number of items gets too large for memory. You could avoid the memory problem by using xrange(), which is restricted to ints. You can, however, write a generator to operate over a series of such longs. I don't believe Python 3.x range has any constraints, and it's already a generator, so you'll have to be more specific about what your environment is. -- DaveA I am using Python 2.7. I don't think range() can take large values. example: I took a = 100 (10^18); This is the max limit in a puzzle. python showed the following error :OverflowError: range() has too many items. I even tried using xrange(), I didn't solve the issue.. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] how to handle very large numbers
Well, I have been doing a puzzle where I have to deal with number 10^18. A variable can store that value but can't do operations.Ex: If I use range() on it, it shows overflow error. So, How do I handle this. I have to use range() for that number.. in this instance. Also mention how to handle in other cases too (A small tutorial/ book would be appreciated ) Thanks___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] where I am going wrong?
This is a project Euler puzzle. http://projecteuler.net/problem=30 I applied brute force way and here is my code k=0for p in range(1,10): for q in range(0,10): for r in range(0,10): for s in range(0,10): for t in range(0,10): n = (p*1)+ (q*1000) + (r*100) + (s*10) + (t*1) if n == \ p**5 + q**5 + r**5 + s**5 + t**5: print n k+=nprint k My answer: 240559 But its showing the answer as wrong!!. I used the same method on the example puzzle and it worked. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] where I am going wrong?
From: waynejwer...@gmail.com Date: Wed, 14 Dec 2011 08:25:53 -0600 Subject: Re: [Tutor] where I am going wrong? To: sur...@live.com CC: tutor@python.org On Wed, Dec 14, 2011 at 8:13 AM, surya k sur...@live.commailto:sur...@live.com wrote: This is a project Euler puzzle. http://projecteuler.net/problem=30http://projecteuler.net/problem%3d30 I applied brute force way and here is my code k=0for p in range(1,10):for q in range(0,10):for r in range(0,10):for s in range(0,10):for t in range(0,10): n = (p*1)+ (q*1000) + (r*100) + (s*10) + (t*1) if n == \ p**5 + q**5 + r**5 + s**5 + t**5:print n k+=nprint k My answer: 240559 But its showing the answer as wrong!!. I used the same method on the example puzzle and it worked. Your email client broke the formatting - you should probably use plain-text or a pastebin. -Wayne This is a project Euler puzzle. http://projecteuler.net/problem=30 I applied brute force way and here is my codek=0for p in range(1,10): for q in range(0,10): for r in range(0,10): for s in range(0,10): for t in range(0,10): n = (p*1)+ (q*1000) + (r*100) + (s*10) + (t*1) if n == p**5 + q**5 + r**5 + s**5 + t**5: k+=nprint kMy answer: 240559But its showing the answer as wrong!!. I used the same method on the example puzzle and it worked. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] where I am going wrong?
From: sur...@live.com To: waynejwer...@gmail.com CC: tutor@python.org Subject: RE: [Tutor] where I am going wrong? Date: Wed, 14 Dec 2011 19:59:24 +0530 From: waynejwer...@gmail.com Date: Wed, 14 Dec 2011 08:25:53 -0600 Subject: Re: [Tutor] where I am going wrong? To: sur...@live.com CC: tutor@python.org On Wed, Dec 14, 2011 at 8:13 AM, surya k sur...@live.commailto:sur...@live.com wrote: This is a project Euler puzzle. http://projecteuler.net/problem=30http://projecteuler.net/problem%3d30 I applied brute force way and here is my code k=0for p in range(1,10): for q in range(0,10): for r in range(0,10): for s in range(0,10): for t in range(0,10): n = (p*1)+ (q*1000) + (r*100) + (s*10) + (t*1) if n == \ p**5 + q**5 + r**5 + s**5 + t**5: print n k+=nprint k My answer: 240559 But its showing the answer as wrong!!. I used the same method on the example puzzle and it worked. Your email client broke the formatting - you should probably use plain-text or a pastebin. -Wayne This is a project Euler puzzle. http://projecteuler.net/problem=30I applied brute force way and here is my codek=0for p in range(1,10):for q in range(0,10): for r in range(0,10): for s in range(0,10): for t in range(0,10): n = (p*1)+ (q*1000) + (r*100) + (s*10) + (t*1) if n == p**5 + q**5 + r**5 + s**5 + t**5: k+=n print kMy answer: 240559But its showing the answer as wrong!!.I used the same method on the example puzzle and it worked. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] where I am going wrong?
Date: Wed, 14 Dec 2011 10:39:53 -0500 From: d...@davea.name To: sur...@live.com CC: waynejwer...@gmail.com; tutor@python.org Subject: Re: [Tutor] where I am going wrong? On 12/14/2011 09:29 AM, surya k wrote: From: waynejwer...@gmail.com Date: Wed, 14 Dec 2011 08:25:53 -0600 Subject: Re: [Tutor] where I am going wrong? To: sur...@live.com CC: tutor@python.org On Wed, Dec 14, 2011 at 8:13 AM, surya k sur...@live.commailto:sur...@live.com wrote: This is a project Euler puzzle. http://projecteuler.net/problem=30http://projecteuler.net/problem%3d30 I applied brute force way and here is my code k=0for p in range(1,10):for q in range(0,10):for r in range(0,10):for s in range(0,10):for t in range(0,10): n = (p*1)+ (q*1000) + (r*100) + (s*10) + (t*1) if n == \ p**5 + q**5 + r**5 + s**5 + t**5:print n k+=nprint k My answer: 240559 But its showing the answer as wrong!!. I used the same method on the example puzzle and it worked. Your email client broke the formatting - you should probably use plain-text or a pastebin. -Wayne This is a project Euler puzzle. http://projecteuler.net/problem=30 I applied brute force way and here is my codek=0for p in range(1,10): for q in range(0,10): for r in range(0,10): for s in range(0,10): for t in range(0,10): n = (p*1)+ (q*1000) + (r*100) + (s*10) + (t*1) if n == p**5 + q**5 + r**5 + s**5 + t**5: k+=nprint kMy answer: 240559But its showing the answer as wrong!!. I used the same method on the example puzzle and it worked. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor The new copy you posted was just as bad. Please tell your email program not to reformat your text. With Thunderbird, I do that by telling it to use plain-text format for any message that goes to the domain: python.org. It's under File-preferences-Composition-General-Send Options. First section Convert the message to plain text and second section, under PlainTextDomain, add python.org I tried to reflow the source. But 59 columns of indentation is pretty wild. So I also changed indentation, and maybe got it right. Your code assumes all the numbers it will find will be 5 digit numbers, which is a strange assumption. When I try it with **4, I get zero as the result. All the numbers for that case happen to be exactly 4 digits, while you have 5 nested loops. There's no reason to presuppose the number of digits. I therefore changed the p range to 0,10, and the if statement to exclude the solution for 0 and 1. I also added a global called exp, so we can run it unchanged on either 4 or 5. exp = 4 k=0 for p in range(0,10): for q in range(0,10): for r in range(0,10): for s in range(0,10): for t in range(0,10): n = (p*1)+ (q*1000) + (r*100) + (s*10) + (t*1) if n == p**exp + q**exp + r**exp + s**exp + t**exp and p1: k+=n print one part, n print k This still doesn't get the right answer, because it misses at least one number that has more than 5 digits. If you just want to get on with it, you could nest several more for-loops. But you can readily put a coarse upper limit on the largest match, by trying something like 10* 9**5. See how big that is, and if it's less than 10 digits long, you have an upper limit. Now you know how many loops you need. There are other approaches that don't require you to make a large number of nested loops. One is to use recursion. Another is to just iterate through the integers (n), then use str() and list() to turn it into a bunch of digits, which you then raise to the appropriate power in a simple loop. -- DaveA Thanks Dave for putting that much effort.Actually, I was using plane text format.. I wonder what went wrong! So, regarding the program, you assumed it correctly. Let me do it again as you said.. I'll let you know if there is any problem Thanks___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] best book for OOP
I'm reading Core Python Programming - Chun.. Currently, I am studying OOP in it.. and I feel there is something I am missing in that while studying. Actually I am from C.. so, no idea of OOP. Could you tell me the best, simple, easy to understand book!! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] how to handle big numbers
Finding factorial of 8 or 9 isn't big. If I would like to find factorial of 32327, how can I ?? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to handle big numbers
Date: Fri, 9 Dec 2011 14:53:07 -0500 From: d...@davea.name To: sur...@live.com CC: tutor@python.org Subject: Re: [Tutor] how to handle big numbers On 12/09/2011 02:25 PM, surya k wrote: Finding factorial of 8 or 9 isn't big. If I would like to find factorial of 32327, how can I ?? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor How close do you want your answer? The gamma function can be used to calculate it, but it won't be precise. I don't know how many digits are in 32327!, but it must be at least hundreds of thousands, and a float cannot represent that exactly. In fact it cannot represent a number that big, even approximately. It might be millions of digits, but I don't have the time right now to figure it out. If you use a long int (which int will promote to, automatically), you could do the calculation with a very simple program, providing you don't run out of either time or memory. if it were my problem, I'd do it in three steps. First write a program to calculate N! exactly. See how long it takes for 100, and how many digits are in the answer. Then try it again for 1000! Next, I'd look up the gamma function, and figure out how large the desired value will be. Finally, depending on what I got from those first two, I'd either run the first program with 32327, and wait a long time, or write a specialized math package to calculate the gamma function to whatever precision I thought Ineeded. -- DaveA Well, its in a puzzle.. everything is done except this part. I need to calculate N! ( max value of N is 10^6). ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] how to calculate program compile time?
I'm doing puzzles where we need to write code that works as fast a possible So, how can I check the compile time of my program ?... ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] unable to use find(), index()
I am using the following code astr = foobarstr1 =fooastr.find(str1, beg=0, end=3) This is showing the following error Traceback (most recent call last): File interactive input, line 1, in moduleTypeError: find() takes no keyword arguments I even tried by importing string module, but it isn't working. This same problem with find() Could you please help me! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] how to use int and split() simultaneously
This is something I am trying to do.. Say, we are entering a string 1 2 3 4 5.so, I want to assign the numbers directly as numbers. how can I do it? I could put that numbers as string but not as number.. strNum = raw_input('enter:').split() I can convert the list into numbers by doing this... for i in range(len(strNum)): strNum[i] = int(strNum[i]). but I feel, its a long process. How can I do it in the shortest possible way?? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] how to find index of list with its value
Well, we all know to know the value when we have the index of a list. But how can we find it in the reverse way... say a listl=[1,2,3,4] l[0]=1.but how can I find its address with its value 1 ?? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] unable to run file though dir path included
I have included the path directory of the file but still I couldn't run it!. 1. I created a .pth file and wrote all required path list's and saved in site-packages of python dir.( python\Lib\Site-packages). 2. I also included python path ( c:\python27\) in system path so as to run it using command prompt. Now when I use this command to run a file foo.py at command prompt ( runcmd ) command: python foo.py.. it isn't running. The following error is shown. python: can't open file 'foo': [ Errno 2] no such file or directory. What should I do? But the following command didn't give me an error in python shell import foo ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] how to link GUI app to the code
I have designed a application using WxGlade but I don't know how to link it to my code and run it.Could you please tell me? at least it would be helpful if you could show me relevant tutorials. Here is the part of the application code that is generated using WxGlade. self.panel_6 = wx.Panel(self.notebook_main_home, -1) self.label_title = wx.StaticText(self.notebook_main_home, -1, Enter Names, style=wx.ALIGN_CENTRE)self.panel_7 = wx.Panel(self.notebook_main_home, -1)self.label_name1 = wx.StaticText(self.notebook_main_home, -1, Name 1, style=wx.ALIGN_CENTRE)self.text_ctrl_name1 = wx.TextCtrl(self.notebook_main_home, -1, )self.text_ctrl_output = wx.TextCtrl(self.notebook_main_home, -1, , style=wx.TE_READONLY) self.label_name2 = wx.StaticText(self.notebook_main_home, -1, Name 2) self.text_ctrl_name2 = wx.TextCtrl(self.notebook_main_home, -1, ) self.panel_5 = wx.Panel(self.notebook_main_home, -1)self.panel_8 = wx.Panel(self.notebook_main_home, -1)self.button_submit = wx.Button(self.notebook_main_home, -1, Submit)self.panel_9 = wx.Panel(self.notebook_main_home, -1) Those bold lines are where I suppose to give controls. 1. self.text_ctrl_name1 : here I need to give input name12. self.text_ctrl_name2 : here I need to give input name23. self.button_submit: The program should take the above input values after clicking this button4. self.text_ctrl_output : here I need to get output. As far as my program is concerned, its just a small string manipulation program based upon the input names. How could I do this? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] where python is used in real world
I don't understand why python doesn't provide executable files for the source code. I am using py2exe for building executables and I found that, it doesn't completely change code into binary but creates dll files and python libraries to run that particular code. This process makes program very large although it isn't. 1. Why doesn't python doesn't offer executable file ? 2. If one wants to make a commercial software using python, how can he hide the code? 3. However, if one wants to make an open source software, as python doesn't offer executable files, how people make those so as to distribute their products to people?___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] unexpected list entry
Hi, Just take a look at this small code.. I am just taking a string as input and assigning it as a list. But I am finding an unexpected entry in the list.. Why this is happening? I am using PyScripter IDE. code : #!/usr/bin/env python def main(): pass if __name__ == '__main__': main() print Flames: name1 = raw_input('enter name 1') ListName1 = list(name1) print name1 print ListName1 Output: Flames: foo [u'f', u'o', u'o'] Observe the last line.. it isn't showing [ 'f', 'o', 'o'] Why is that u coming in the middle from no where ??___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] unexpected list entry
Thanks for the information about unicode. Actually, I am using python 2.7 in Windows XP. IDE: PyScripter. So, I run the same code in IDLE (Python 2.7).. Its working. It isn't showing the list in unicode format! I've used PyScripter many times before and worked on lists.. but I never faced any problem like this -- From: Dave Angel d...@davea.name Sent: Friday, December 02, 2011 7:43 PM To: surya k sur...@live.com Cc: Python Tutor tutor@python.org Subject: Re: [Tutor] unexpected list entry On 12/02/2011 08:49 AM, surya k wrote: Hi, Just take a look at this small code.. I am just taking a string as input and assigning it as a list. But I am finding an unexpected entry in the list.. Why this is happening? I am using PyScripter IDE. code : #!/usr/bin/env python def main(): pass if __name__ == '__main__': main() print Flames: name1 = raw_input('enter name 1') ListName1 = list(name1) print name1 print ListName1 Output: Flames: foo [u'f', u'o', u'o'] Observe the last line.. it isn't showing [ 'f', 'o', 'o'] Why is that u coming in the middle from no where ?? The u notation just says it's a unicode string. No more confusing than the [] meaning it's a list. Neither is the content of the object, just showing you textually what the type is. You should also print repr(name1) to see if it is likewise a unicode string. I presume it's already unicode when returned by raw_input(). My puzzle is how you got unicode strings, if you've shown your entire program. In Python3, all strings are unicode, so it wouldn't bother to say so. Besides, your code has a syntax error in it, if it's supposed to be Python 3.x You probably need to identify your particular version of Python, and the platform (OS) you're running it on. But it could be affected by your IDE (Pyscripter), or by a site.py or other implicitly loaded module. You can check for the former by running the script from a command shell. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] unexpected list entry
One more thing I want to mention.. I think there is a problem in the IDE itself. I have faced some problems with this IDE before... (Not with this) Could you please tell me a free python IDE (No Eclipse/ Netbeans) -- From: Dave Angel d...@davea.name Sent: Friday, December 02, 2011 7:43 PM To: surya k sur...@live.com Cc: Python Tutor tutor@python.org Subject: Re: [Tutor] unexpected list entry On 12/02/2011 08:49 AM, surya k wrote: Hi, Just take a look at this small code.. I am just taking a string as input and assigning it as a list. But I am finding an unexpected entry in the list.. Why this is happening? I am using PyScripter IDE. code : #!/usr/bin/env python def main(): pass if __name__ == '__main__': main() print Flames: name1 = raw_input('enter name 1') ListName1 = list(name1) print name1 print ListName1 Output: Flames: foo [u'f', u'o', u'o'] Observe the last line.. it isn't showing [ 'f', 'o', 'o'] Why is that u coming in the middle from no where ?? The u notation just says it's a unicode string. No more confusing than the [] meaning it's a list. Neither is the content of the object, just showing you textually what the type is. You should also print repr(name1) to see if it is likewise a unicode string. I presume it's already unicode when returned by raw_input(). My puzzle is how you got unicode strings, if you've shown your entire program. In Python3, all strings are unicode, so it wouldn't bother to say so. Besides, your code has a syntax error in it, if it's supposed to be Python 3.x You probably need to identify your particular version of Python, and the platform (OS) you're running it on. But it could be affected by your IDE (Pyscripter), or by a site.py or other implicitly loaded module. You can check for the former by running the script from a command shell. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] unexpected list entry
-- From: Dave Angel d...@davea.name Sent: Friday, December 02, 2011 9:36 PM To: surya k sur...@live.com Cc: Python Tutor tutor@python.org Subject: Re: [Tutor] unexpected list entry (You top-posted. Put your remarks AFTER whatever you quote from earlier messages) On 12/02/2011 10:47 AM, surya k wrote: Thanks for the information about unicode. Actually, I am using python 2.7 in Windows XP. IDE: PyScripter. So, I run the same code in IDLE (Python 2.7).. Its working. It isn't showing the list in unicode format! Nothing to do with list. Reread my remarks. The string is apparently unicode, presumably from the raw_input() call. The IDE must be changing the type of stdin to make it unicode. Did you try print repr(name1) ? I'll bet that's also a unicode string. And you tried it in another IDE, IDLE. But the key question is how it behaves in raw Windows, from a command prompt. The user of your code is unlikely to set up your particular IDE to run something you've written. As for an IDE, the only free one I use is emacs. I've heard good things about pywin (or something like that), a free IDE that comes with the free ActiveState python. The Active State python also includes some extensions specifically for Windows, and to make it easier to use Windows dll's and com objects. I used to use the ActiveState stuff when I used Windows. The following material is out of order, but I left it in anyway, for some context. I've used PyScripter many times before and worked on lists.. but I never faced any problem like this -- From: Dave Angel d...@davea.name Sent: Friday, December 02, 2011 7:43 PM To: surya k sur...@live.com Cc: Python Tutor tutor@python.org Subject: Re: [Tutor] unexpected list entry On 12/02/2011 08:49 AM, surya k wrote: Hi, Just take a look at this small code.. I am just taking a string as input and assigning it as a list. But I am finding an unexpected entry in the list.. Why this is happening? I am using PyScripter IDE. code : #!/usr/bin/env python def main(): pass if __name__ == '__main__': main() print Flames: name1 = raw_input('enter name 1') ListName1 = list(name1) print name1 print ListName1 Output: Flames: foo [u'f', u'o', u'o'] Observe the last line.. it isn't showing [ 'f', 'o', 'o'] Why is that u coming in the middle from no where ?? The u notation just says it's a unicode string. No more confusing than the [] meaning it's a list. Neither is the content of the object, just showing you textually what the type is. You should also print repr(name1) to see if it is likewise a unicode string. I presume it's already unicode when returned by raw_input(). My puzzle is how you got unicode strings, if you've shown your entire program. In Python3, all strings are unicode, so it wouldn't bother to say so. Besides, your code has a syntax error in it, if it's supposed to be Python 3.x You probably need to identify your particular version of Python, and the platform (OS) you're running it on. But it could be affected by your IDE (Pyscripter), or by a site.py or other implicitly loaded module. You can check for the former by running the script from a command shell. -- DaveA -- DaveA Dave, I am now puzzled.. I don't understand but the list is now not showing unicode. I just restarted the IDE and rewrote the code again! however, I tried print repr(name1), it didn't show me any unicode notation. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] why doesn't python show error
1. Why doesn't python show error(description given below) at the beginning when we use functions which aren't present in the standard modules... Example: TheString = raw_input('enter a string')lengthofStr = strlen(TheString)Look closely, I used a wrong function to find length of the string. [ strlen( ) belongs to C ].When I run the program, it didn't show any error but when entered input, it then showed up!.Why python doesn't show error at the beginning just like C does?2. Why doesn't python create executable file (.exe ) when we run the code.. If this doesn't do, how can I share my program.. does everyone need to have python to check others code and know what it does? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] why doesn't python show error
Thanks for that information. I understood what you are saying but in general when python doesn't give us executable files (whether its in Mac/ Linux/ Windows).. how could people develop programs ?. At some point of time people need to provide a file that runs without the help of a python interpreter.. From: Sarma Tangirala Sent: Monday, November 28, 2011 3:46 PM To: surya k Cc: Python Tutor Subject: Re: [Tutor] why doesn't python show error On 28 November 2011 15:23, surya k sur...@live.com wrote: 1. Why doesn't python show error(description given below) at the beginning when we use functions which aren't present in the standard modules... Example: TheString = raw_input('enter a string')lengthofStr = strlen(TheString)Look closely, I used a wrong function to find length of the string. [ strlen( ) belongs to C ].When I run the program, it didn't show any error but when entered input, it then showed up!.Why python doesn't show error at the beginning just like C does?2. Why doesn't python create executable file (.exe ) when we run the code.. If this doesn't do, how can I share my program.. does everyone need to have python to check others code and know what it does? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor The thing is, python does not compile code like C does. It interprets each line. So as you say, it runs. Errors turn up only when they are encountered. http://en.wikipedia.org/wiki/Interpreted_language But python does have a compile version, I believe jython does this. There are a couple of programs that generate executable, py2exe on Win for example. http://stackoverflow.com/questions/2933/an-executable-python-app -- Sarma Tangirala, Class of 2012, Department of Information Science and Technology, College of Engineering Guindy - Anna University ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Multiplater gaming
I am building a multiplayer game (Game:Bingo) where friends(players) connect over internet. In this particular game, users sends a character/ number to all other players.. Can you please shed some light on it. I've been looking into 'Core Python Programming' book by Chun but I couldn't understand clearly. So, If possible, please provide links to related free e-books / tutorials. my another question is.. do I need to setup any external hardware infrastructure to get this done ?? Thanks for sparing your valuable time on this! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Writing Game in python
Hi, Actually, I want to develop a multiplayer Bingo game. So, I would like to develop it in python C. As I am not familiar with game development, could you please tell me what libraries I should use for development?... etc ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Writing Game in python
Thanks for your reply. Actually, I am good at writing code in C and still learning python(Familiar with basics). Now, I am much inclined towards python than C and trying to use it more. I love it. Coming back to the game I want to develop.. I didn't put any code yet but I finished with the algorithm part. All I can tell you is.. Its a small board game, Bingo!. Its typical game we seldom use to play in school on a piece of paper. From: waynejwer...@gmail.com Date: Sun, 27 Nov 2011 08:05:46 -0600 Subject: Re: [Tutor] Writing Game in python To: sur...@live.com CC: tutor@python.org On Sun, Nov 27, 2011 at 7:52 AM, surya k sur...@live.com wrote: Hi, Actually, I want to develop a multiplayer Bingo game. So, I would like to develop it in python C. As I am not familiar with game development, could you please tell me what libraries I should use for development?... etc You could easily develop the game entirely in Python. As for libraries... well it depends on what you're trying to do. If you want a GUI you'll want to look at one of the frameworks like Tkinter, PyGTK+, wxPython, or QtPython. Alternatively you could look at the PyGame library which is geared towards game development. If you want to do internet communication, you'll want to investigate the socket module, and possibly the threading module. How familiar are you with Python? Have you written any programs before? What would really help is if you gave us some psuedocode of your algorithm or the steps you think each piece should need to accomplish. We like to see that you've at least tried to do something. HTH,Wayne ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Writing Game in python
I think I have got enough tail to catch up and start my project..Thanks to all who have spared some time to help me. From: waynejwer...@gmail.com Date: Sun, 27 Nov 2011 08:05:46 -0600 Subject: Re: [Tutor] Writing Game in python To: sur...@live.com CC: tutor@python.org On Sun, Nov 27, 2011 at 7:52 AM, surya k sur...@live.com wrote: Hi, Actually, I want to develop a multiplayer Bingo game. So, I would like to develop it in python C. As I am not familiar with game development, could you please tell me what libraries I should use for development?... etc You could easily develop the game entirely in Python. As for libraries... well it depends on what you're trying to do. If you want a GUI you'll want to look at one of the frameworks like Tkinter, PyGTK+, wxPython, or QtPython. Alternatively you could look at the PyGame library which is geared towards game development. If you want to do internet communication, you'll want to investigate the socket module, and possibly the threading module. How familiar are you with Python? Have you written any programs before? What would really help is if you gave us some psuedocode of your algorithm or the steps you think each piece should need to accomplish. We like to see that you've at least tried to do something. HTH,Wayne ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] How to handle conjunction operators
Hi, Could you please tell me why this isn't working and how can I make it possible... Consider this code..name = raw_input(Enter your first name: ) if name[0] == (m or f or b) : rhyme = name[1:]What I want here is.. If the name starts with 'm' or 'f' or 'b', The first letter should be removed.But this isn't happening here. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] taking input for a list in a list
Hi, Actually my programming language is C.. learning python. I'm trying to write sudoku program for which I need to take input. This is what I did merely *list = [] for i in range (0,4) : for j in range (0,4) : list[i][j].append ( int (raw_input(Enter) ) ) * This is completely wrong.. but I couldn't handle this kind of.. how do I.. Actually I need a list in a list to handle sudoku. for a simple list to get input.. this would obviously work.. *list.append ( int(raw_input(Enter) )* Can you tell me how do I do this correctly ? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] integrating python and C
Hi! Actually, I'm writing sudoku solver. So, I'd write my logic in C but when it comes to GUI, I feel that python is much easier than doing in C. What I'm looking at is, take input from python program with graphic interface and passing it to my C program file then solve the puzzle and again passing the whole array to python code to display.. How should I do it. Thanks. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] largest palindrome number
If you take a close look at my code. for i in range (1,100) : for j in range (i,100) : Temp = palindrome(i*j) here, as the loop goes on, i*j can never become smaller in any case. which is why I think it, as long as PNum gets a new number, its bigger palindrome than the previous.. so, at the end of the loop. we'll get largest palindrome number.. On 8/25/11, Hugo Arts hugo.yo...@gmail.com wrote: On Thu, Aug 25, 2011 at 6:49 PM, surya k sur...@live.com wrote: Hi, I'm doing a puzzle where it asked me to find the largest palindrome number formed by the product of two three-digit numbers. They mentioned an example saying that 9009 is the largest palindrome number formed by two two-digit numbers (99 * 91). I've written my code this way.. and I tested it with the given example and I got it right! Logic I used : largest two digit number is 99 and three digit number is 999.. so largest product of two two-digit numbers is 100*100 and for three-digit numbers is 1000*1000. So, I used a for loop and it assigns a palindromic value to PNum till it is 100*100 (for 2 digit number) and 1000*1000 (for three-digit number).. Thus it stops at the max possible palindromic value, which is what we want. def palindrome (n) : TempN = n rev = 0 while n != 0 : k = n % 10 rev = (rev * 10) + k n = n / 10 if TempN == rev : return TempN # Palindrome else : return 0 # not Palindrome for i in range (1,100) : for j in range (i,100) : Temp = palindrome(i*j) if Temp 1 and Temp != 0 : PNum = Temp print PNum So, for getting the largest palindrome number formed by two three-digit numbers, I changed 100 to 1000 and 1,00,00 to 1,000,000 in the highlighted area. Thus I got the answer to be 88. When I submitted the answer, its saying wrong! Where I'm going wrong ? help me, please ! When you get a new palindrome, you should make sure it's bigger than the one you already have before you replace the old one. 88 is the last palindrome you find, but it is not the the biggest. You cannot assume the biggest one will be found last. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] largest palindrome number
Hi, I'm doing a puzzle where it asked me to find the largest palindrome number formed by the product of two three-digit numbers. They mentioned an example saying that 9009 is the largest palindrome number formed by two two-digit numbers (99 * 91). I've written my code this way.. and I tested it with the given example and I got it right! *Logic I used :* largest two digit number is 99 and three digit number is 999.. so largest product of two two-digit numbers is 100*100 and for three-digit numbers is 1000*1000. So, I used a for loop and it assigns a palindromic value to *PNum* till it is 100*100 (for 2 digit number) and 1000*1000 (for three-digit number).. Thus it stops at the max possible palindromic value, which is what we want. def palindrome (n) : TempN = n rev = 0 while n != 0 : k = n % 10 rev = (rev * 10) + k n = n / 10 if TempN == rev : return TempN # Palindrome else : return 0 # not Palindrome for i in range (1,100) : for j in range (i,100) : Temp = palindrome(i*j) if Temp 1 and Temp != 0 : PNum = Temp print PNum So, for getting the largest palindrome number formed by two three-digit numbers, I changed 100 to 1000 and 1,00,00 to 1,000,000 in the highlighted area. Thus I got the answer to be 88. When I submitted the answer, its saying wrong! Where I'm going wrong ? help me, please ! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] getting error while solving a series that estimates the value of pi
Hi, The problem is to estimate the value of pi using the following series. *1 / pi = (( 2 * sqrt(2) )/ 9801 ) * SIGMA of k[ (4k)! (1103 + 26390*k) / (k!^ 4 ) * 396^(4k) ]* *where k is [0, infinity)* * Problem is located at : ThinkPython Book, www.thinkpython.org *Pg 89, Exercise 7.5, Think Python Book. * * * the series should be considered till the last term of the sigma must be 1e-15 I have written the below code : *# program estimates the value of pi* *# Ramanujan's series... * *import math* * * *def fact(n) : # def of factorial function.* *if n 0 :* * return n * fact(n-1)* *if n == 0 :* * return 1* * * *k = 0* *tot = 0* *temp1 = 0* *while k = 0 and temp1 == 0 :* * * * a = ( 2 * math.sqrt(2) ) / 9801 # first term before sigma * * nu = fact (4*k) * (1103 + (26390*k) ) # numerator of series* * de = pow( fact(k), 4 ) * pow ( 396, 4*k ) # denominator of series* * * * if de / nu 1e-15 : * *temp = nu / de* *tot = tot + temp* *temp1 = 0 * *k = k + 1 * * elif de / nu == 1e-15 :* * series = a * tot * * k = k + 1* * temp1 = 0* * elif de / nu 1e-15 :* * print series* * temp1 = 1* I am getting the following error : which is completely surprising! *Traceback (most recent call last):* * File pi.py, line 30, in module* *print series* *NameError: name 'series' is not defined* * * Thus I have removed name 'series' and replaced with *a*tot, * now I am getting this error *Traceback (most recent call last):* * File pi.py, line 30, in module* *print 1 / (a * tot)* *ZeroDivisionError: float divisio*n Thus I changed the first highlighted lines to *nu = float (fact (4*k) * (1103 + (26390*k) ) )* * de = float (pow( fact(k), 4 ) * pow ( 396, 4*k )) * now I am getting * Traceback (most recent call last):* * File pi.py, line 18, in module* *de = float (pow( fact(k), 4 ) * pow ( 396, 4*k ) )* *OverflowError: long int too large to convert to float* *help me out of this problem, how could I fix this* ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] getting error while solving a series that estimates the value of pi
Let me write the code again.. Thanks for your help. On Mon, Jul 18, 2011 at 10:38 PM, James Reynolds eire1...@gmail.com wrote: On Mon, Jul 18, 2011 at 12:10 PM, surya k sur...@live.com wrote: Hi, The problem is to estimate the value of pi using the following series. *1 / pi = (( 2 * sqrt(2) )/ 9801 ) * SIGMA of k[ (4k)! (1103 + 26390*k) / (k!^ 4 ) * 396^(4k) ]* *where k is [0, infinity)* * Problem is located at : ThinkPython Book, www.thinkpython.org *Pg 89, Exercise 7.5, Think Python Book. * * * the series should be considered till the last term of the sigma must be 1e-15 I have written the below code : *# program estimates the value of pi* *# Ramanujan's series... * *import math* * * *def fact(n) : # def of factorial function.* *if n 0 :* * return n * fact(n-1)* *if n == 0 :* * return 1* * * *k = 0* *tot = 0* *temp1 = 0* *while k = 0 and temp1 == 0 :* * * * a = ( 2 * math.sqrt(2) ) / 9801 # first term before sigma * * nu = fact (4*k) * (1103 + (26390*k) ) # numerator of series* * de = pow( fact(k), 4 ) * pow ( 396, 4*k ) # denominator of series * * * * if de / nu 1e-15 : * *temp = nu / de* *tot = tot + temp* *temp1 = 0 * *k = k + 1 * * elif de / nu == 1e-15 :* * series = a * tot * * k = k + 1* * temp1 = 0* * elif de / nu 1e-15 :* * print series* * temp1 = 1* I am getting the following error : which is completely surprising! *Traceback (most recent call last):* * File pi.py, line 30, in module* *print series* *NameError: name 'series' is not defined* * * Thus I have removed name 'series' and replaced with *a*tot, * now I am getting this error *Traceback (most recent call last):* * File pi.py, line 30, in module* *print 1 / (a * tot)* *ZeroDivisionError: float divisio*n Thus I changed the first highlighted lines to *nu = float (fact (4*k) * (1103 + (26390*k) ) )* * de = float (pow( fact(k), 4 ) * pow ( 396, 4*k )) * now I am getting * Traceback (most recent call last):* * File pi.py, line 18, in module* *de = float (pow( fact(k), 4 ) * pow ( 396, 4*k ) )* *OverflowError: long int too large to convert to float* *help me out of this problem, how could I fix this* ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor I am getting the following error : which is completely surprising! You only define series when nu/de == XXX. Just don't print series outside of where it is defined, or print it outside of the while loop if you can be assured it is defined when the while loop ends. Even so, you would still end up with the overflow error, because you have de / nu and I'm assuming you want nu / de. As an aside, you might want to consider creating a variable above all the if statements called nude = nu / de and replace all of the nu / de 's to nude. This way you only divide once and not (potentially) three times per loop. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor