I'm trying to implement a fairly simple card game in Python so that two players can play together other the Internet. I have no problem with doing the GUI, but I don't know the first thing about how to do the networking part. A couple libraries I've found so far:
PyRO: seems nice and seems to fit the problem nicely by having shared Card objects in various states.
Twisted with pyglet-twisted: this looks powerful but complicated; I've used Pyglet before though so maybe it wouldn't be too bad.
Can anyone recommend the most appropriate one for my game (not necessarily on this list, I've probably missed lots of good ones)?
Both of those libraries are very good and would work perfectly for your card game.
Pyro might be easier to learn and use, but Twisted will scale better if you ever want to move into a very large number of players.
Twisted can be daunting at first but there are some books to help you get over the hump.
The are some other libraries to choose from but the two you found are mature and used widely within the Python community so you'll have a better chance of finding people to answer any questions.
My personal recommendation would be to use Pyro if you're just wanting to play around with networking but go with Twisted if you have grand plans for lots of players on the internet.
If you decide you don't want to use a 3rd party library, I'd recommend the asynchat module in the standard library. It's perfect for sending/receiving through a simple protocol.
Twisted is the better of the two libraries but the time spent learning to use it but learning networking will take you similar amount of time (at least for me).
If I were you I'd rather learn networking it will be much more useful to you in the future. The concepts are the same for most languages so its more portable as well. If you are going to take this approach have a look at http://www.amk.ca/python/howto/sockets/ it will take you through everything.
Related
(I'm a first-time poster and I think the guidelines don't exclude my question, but I added a more specific example just in case. I apologize if this turns out to be a subjective matter, I just assume there must be a proper standard way of doing this).
I'm a cognitive psychologists and currently supervising some students in a coding club. Since I never "properly" learned how to code, I tend to use the libraries I come across in the work of other researchers or the ones used in the tutorials. However, I realize this might not be the most efficient, straightforward or logic choice.
My question: What is the best practice in selecting a module and library? Is there a structured way to go about this?
A specific simple example: if I want to call a screen in an experiment, I know I can set it up with Pygaze, Psychopy or Pygame. I know each has their own pros and cons, but how do I know there isn't a more suitable one (or should I not care)? Is it better to pick a library that I can use for more components in the code (such as keyboard, timers, etc) or is it better to tailor this choice?
first post here on stack overflow, hoping to get some advice on how to construct a simulation program akin to the 1993 maxis simulator known as El-Fish wiki here , Also, game info here .
Are there known "Simulation system" algorithm groups that can function and create real life interaction etc... e.g. the visualization known as 'flocking' ? Or, is there an open-source code base to study off of already in construction?
Programming wise, would this also be able to be easily done in a purely functional language? if done in an OOP way, i was thinking of prototyping it in python.
Anyways thanks for any direction in pointing me towards a good starting place. I hope to build a graphical view of an idea/data world. It will be hopefully controlled by underlying simulation AI(heuristics maybe?)
In terms of simulation systems, I recommend you search for "agent-based modeling" software. There are a lot of free toolkits available. The two I like the most are NetLogo and Repast.
Also, it looks like you are implementing a "genetic algorithm". There are many good books and pages on that topic.
Python is good, but so are many other languages.
Most of your time will be spent doing the graphics: animating the fish so they look realistic. Unless you can find a free fish-animation-library.
I recommend you try my own GarlicSim framework. It's written in Python and you'll be writing your specific simulation in Python.
It can definitely handle the kind of simulation you want. There are tutorials available which will teach you the basics of GarlicSim in 30 minutes. I'll be happy to help you build your simulation package, just say hello on the mailing list and I'll guide you from there.
I'm not sure about "real life", but there is a flocking algorithm called boids that might be a good example to start from. There are a couple python versions of it as well. There's one that is an example in the owyl project on google code.
I'm a hobbyist programmer (only in TI-Basic before now), and after much, much, much debating with myself, I've decided to learn Python. I don't have a ton of free time to teach myself a hundred languages and all programming I do will be for personal use or for distributing to people who need them, so I decided that I needed one good, strong language to be good at. My questions:
Is python powerful enough to handle most things that a typical programmer might do in his off-time? I have in mind things like complex stat generators based on user input for tabletop games, making small games, automate install processes, and build interactive websites, but probably a hundred things along those lines
Does python handle networking tasks fairly well?
Can python source be obfuscated, or is it going to be open-source by nature? The reason I ask this is because if I make something cool and distribute it, I don't want some idiot script kiddie to edit his own name in and say he wrote it
And how popular is python, compared to other languages. Ideally, my language would be good and useful with help found online without extreme difficulty, but not so common that every idiot with computer knows python. I like the idea of knowing a slightly obscure language.
Thanks a ton for any help you can provide.
Is python powerful enough to handle
most things?
Yes. Period. Study EveOnline game for more information. Look at pygame framework. Free free to use Google to find more.
Does python handle networking tasks
fairly well?
Yes. Look at the number of Python web frameworks plus the Twisted framework. Feel free to use Google to search for Python networking.
Can python source be obfuscated?
Not usefully. This isn't C.
And how popular is python, compared to
other languages?
Look at the TIOBE index.
I think that Python is very powerful to do a lot of things, but just like Java and C++, it often depends on good third-party libraries. I come from a Java background but use Python for a lot of things, and it's been a fun ride. I've done things like statistics, and automation, not sure about the UI though that often depends on the toolkit more than the language.
Python networking works well. I don't know if I'd use it to build a fast algorithmic trading system or a VOIP application, but for most intents and purposes, especially at higher levels of abstraction, it's fine and easy to use. You would need external libraries for things like SSH or FTP.
Python is quite popular and has very good online support, active community, and major corporations (likeGoogle) that use it. I found the official online tutorial and reference to be excellent.
I have to say that I disagree with the "every idiot with a computer" line. There's a difference between knowing a language and using it right, and that's true about every language, even natural ones :) Python does have a lot of functional elements that are not as trivial to use for people coming from a procedural background, so there's always room for growth.
The one problem with Python compared to languages like C and Java is that it is not statically typed. This makes it much faster to write code, but also makes it *much easier) to make mistakes that can be quite nasty to debug. For instance, the same variable can contain a String reference at some point, and a reference to a list of strings at some other point.
Absolutely.
What type of networking? It has socket, http, xml, smtp/pop, telnet, and much more built in.
Python obfuscation won't be nearly as good as a compiled language. Usually that isn't a problem.
It's the 9th most popular tag on stackoverflow, so there's plenty of help available.
Is python powerful enough to handle most things that a typical programmer might do in his off-time? I have in mind things like complex stat generators based on user input for tabletop games, making small games, automate install processes, and build interactive websites, but probably a hundred things along those lines
Definitely. Python is a good tool for all of those except automating install processes, where it might be the right tool but more likely the right tool will likely be decided by what specifically you are automating.
Does python handle networking tasks fairly well?
Yes. You will want to look into Twisted.
Can python source be obfuscated, or is it going to be open-source by nature? The reason I ask this is because if I make something cool and distribute it, I don't want some idiot script kiddie to edit his own name in and say he wrote it
"Open source" refers to the licensing of your code, not the viewability of its source code. Hiding Python source code isn't especially possible, and the results of decompiling Python bytecode will result in much more readable code than the equivalent tools in languages like C. Don't worry about this! You can't prevent people from stealing your car or your computer if they are willing to break the law, and you can't do the same for your code in any language.
And how popular is python, compared to other languages. Ideally, my language would be good and useful with help found online without extreme difficulty, but not so common that every idiot with computer knows python. I like the idea of knowing a slightly obscure language.
This is an unanswerable question. Google will give you lots of conflicting results with different metrics, most of them useful. You're also being a bit silly ;)
As far as learning materials go, I recommend How to Think Like a Computer Scientist, which is a good text that does not presume any existing programming knowledge. It is available for free online, or you could buy a print copy if you prefer. (Don't bother learning 3.x yet. There is not enough library support to do much useful stuff like you want to do, and when there is picking it up will be a breeze; it's not very different than 2.5/6/7.)
Probably yes. Maybe the stat crunching thing will be kinda slow, and maybe a game depending on what kind of game, but generally the performance is good enough, and you save a lot of time on the actual programming. If you REALLY need performance, you can make a module in C, but usually there is a library written to do what you want..
I haven't used it, but there's a framework called Twisted that seems to be pretty good.
No. Bytecode can be decompiled easily, and it only works on a specific version of Python, so your code isn't as portable.
Python is pretty popular, and the Python Package Index has a big list of third party libraries. It's not as widespread as, say, Java, but a lot of people use it and you can probably get answers for what you want.
Points 1 and 2: HELL YEAH.
Point 4: kind of. Python is good at some network stuff. It's not Java or C++. Just use zlib (zip library) and pickle (serialization) for everything, and look at xmlrpclib if you need IPC.
Point 3: No. However, you can write C modules (for the performance critical, and hard-to-copy) parts of your code, and that would make it non-trivial to reverse-engineer.
Python is up to the task (and better) for 1, 2 and 4.
The best solution for 3 from what you describe would probably be to make your programs really open-source with GPL or BSD like licence. This way people will edit your super-cool sources (but often experienced programmers, not just script kiddies) and build on then but leave your name in for posterity.
So this thread is definitely NOT a thread for why Python is better than Ruby or the inverse. Instead, this thread is for objective criticism on why you would pick one over the other to write a RESTful web API that's going to be used by many different clients, (mobile, web browsers, tablets etc).
Again, don't compare Ruby on Rails vs Django. This isn't a web app that's dependent on high level frameworks such as RoR or Django. I'd just like to hear why someone might choose one over the other to write a RESTful web API that they had to start tomorrow, completely from scratch and reasons they might go from one to another.
For me, syntax and language features are completely superfluous. The both offer an abundant amount of features and certainly both can achieve the same exact end goals. I think if someone flips a coin, it's a good enough reason to use one over the other. I'd just love to see what some of you web service experts who are very passionate about their work respond to why they would use one over the other in a very objective format.
I would say the important thing is that regardless of which you choose, make sure that your choice does not leak through your REST API. It should not matter to the client of your API which you chose.
I know Ruby, don't know python... you can see which way I'm leaning toward, right?
Choose the one you're most familiar with and most likely to get things done with the fastest.
Yeah, flip a coin. The truth is that you're going to find minimalist frameworks in either language. Heroku is a pretty strong reason to say Ruby but there may be other similar hosts for Python. But Heroku makes it stupid easy to deploy your api into the cloud whether it's Rails or some other Ruby project that uses Rack. WSGI doesn't give you this option.
As for as the actually implementation though, I'm guessing that you'll find that they're both completely competent languages and both a joy to program in.
I think they are fairly evenly matched in features. I prefer Python, but I have been using it for over a decade so I freely admit that what follows is totally biased.
IMHO Python is more mature - there are more libraries for it (although Ruby may be catching up), and the included libraries I think are better designed. The language evolution process is more mature too, with each proposed feature discussed in public via the PEPs before the decision is made to include them in a release. I get the impression that development of the Ruby language is much more ad-hoc.
Python is widely used in a lot of areas apart from web development - scientific computing, CGI rendering pipelines, distributed computing, Linux GUI tools etc. Ruby got very little attention before Rails came along, so I get the impression that most Ruby work is focused on web development. That may not be a problem if that is all you want to do with the language, but it does mean that Python has a more diverse user base and a more diverse set of libraries.
Python is faster too.
Ruby + Sinatra
Very easy to use with/as rack middleware - someone's already mentioned heroku
Either will do a great job and you'll gain in other ways from learning something new. Why not spend as couple of days with each? See how far you can get with a simple subset of the problem, then see how you feel. For bonus points report back here and answer your own question!
I heard that Python is easy and powerful, but I don't know if I'm on the right track to learn it. I learn from online tutorials, I know basic maths calculation and printing strings, but how long will it take to develop something useful? I don't really know the exact uses of Python, though.
I'm not exactly sure what you're looking for, but I think one or more of the following may be the next step you're looking for.
Perhaps you would like to use a variety of different protocols for a networking program, you could check out Twisted.
Or perhaps if you would like to make a web application or blog you can check out Django.
Or perhaps you would like to make a GUI application, you could take a look at TkInter.
Or perhaps you would like to get into game programming, you could take a look at Pygame.
Or perhaps you would like to ... you can take a look at the Python Package Index.
How long will it take? This depends on your programming background in general. The best way is simply to jump into the topic you're interested in and start on a mini project.
Python is a general purpose language. You can use it to make a lot of different things, but it's best suited at stuff that doesn't require a lot of speed, since the high level features have a performance cost.
It's hard to tell how long it will take you to develop something useful. The other day I made a script to help on a small computer administration thing. You could do that with a week or two of experience (or maybe less), depending on your previous programming knowledge and the amount of time you put into studying. However, if you want to make something bigger (maybe an audio player, an IM client, mid-sized stuff like that), you probably need some weeks or months of practice. It depends a lot on the time and energy you invest in programming.
I'd suggest to follow either the official tutorial or Dive Into Python.
In general, it depends on you. Python can be used for simple or complex stuff, and for many different applications. It depends on what you want.
Have a look at Mark Pilgrim's freely available book called Dive Into Python. I think it's a better choice to start with than online tutorials. The best way to learn a language is to start to work on a project. As I read this book, I started to implement a simple image viewer. As I advanced with the book, I could refine the project progressively. Invent something that is interesting to you.
I also suggest you taking notes when you learn a programming language. When you learn something that can be useful later, make some notes with a simple example, e.g. how to read a text file line by line, convert int to str, convert str to int, basic list operations, etc. Later on you can use these building blocks in a larger project.
Like every other programming language In order to learn Python you need to write a program with it.
Find a pet project and use python to code it. I also recommend Dive into python" (like anyone else that answered your question).
A few months ago I've decided to learn IronPython (.NET implementation of python), I'vve started by reading "Dive into python" and a few tutorials and then I've started coding a simple board game using IronPython (you can read about it in my blog).
In order to learn a new programming language you need to use it and then you'll know how and where to use it.
The best way to learn how to do something useful is come up with something useful you want to do. Make sure it's not way out of your league, then do research to accomplish it. That's how a lot of programmers learn languages.
What other programming background do you have? What programming interests do you have -- web apps, numerical / scientific computations, games, ...? Python is good at many different things, for both beginners and experienced programmers, but the most fruitful approach(es) to it do depend on what you already know, and what really interests you!-)
Bram who invented bittorrent with python says python is good for writing protocols in addition to aforementioned webapps, games and general purpose. Compared to Java python solves same problem in less code and less ways in longer development and VM time where Java has more ways solve same problem in more code and faster VM and faster development time.
Making a comparison between Python, and other languages would not help, as there is always somebody who would find a reason to prefer one language instead of another.
If you want a scripting language that is powerful, but that it is easier to read than perl, that doesn't have a curly bracket syntax, and that allows you to learn something about object oriented programming, then Python is the language for you.