How do I choose modules/libraries in Python? - python

(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?

Related

Does OOP make sense for small scripts?

I mostly write small scripts in python, about 50 - 250 lines of code. I usually don't use any objects, just straightforward procedural programming.
I know OOP basics and I have used object in other programming languages before, but for small scripts I don't see how objects would improve them. But maybe that is just my limited experience with OOP.
Am I missing something by not trying harder to use objects, or does OOP just not make a lot of sense for small scripts?
I use whatever paradigm best suits the issue at hand -- be it procedural, OOP, functional, ... program size is not a criterion, though (by a little margin) a larger program may be more likely to take advantage of OOP's strengths -- multiple instances of a class, subclassing and overriding, special method overloads, OOP design patterns, etc. Any of these opportunities can perfectly well occur in a small script, there's just a somewhat higher probability that it will occur in a larger one.
In addition, I detest the global statement, so if the natural procedural approach would require it, I will almost invariably switch to OOP instead -- even if the only advantage is the ability to use a qualified name instead of the barename which would require global.
There's definitely no need to "try harder" in general -- just ask yourself "is there an opportunity here to use (a) multiple instances (etc etc)" and it will soon become second nature, i.e., you'll spot the opportunities without needing to consciously remind yourself every time to look for them, and your programming will improve as a result.
Object-Oriented Programming, while useful for representing systems as real-world objects (and hopefully making large software system easier to understand) is not the silver bullet to every solution (despite what some people teach).
If your system does not benefit from what OOP provides (things such as data abstraction, encapsulation, modularity, polymorphism, and inheritance), then it would not make sense to incur all the overhead of doing OOP. However, if you find that as your system grows these things become a bigger concern to you, then you may want to consider moving to an OOP solution.
Edit: As an update, you may want to head over to Wikipedia to read the articles on various criticisms of OOP. Remember that OOP is a tool, and just like you wouldn't use a hammer for everything, OOP should not be used for everything. Consider the best tool for the job.
One of the unfortunate habits developed with oop is Objectophrenia - the delusion of seeing objects in every piece of code we write.
The reason why that happens is due our delusion of believing in the existence of a unified objects theorem.
Every piece of code you write, you begin to see it as a template for objects and how they fit into our personal scheme of things. Even though it might be a small task at hand, we get tempted by the question - is this something I could place into my class repository which I could also use for the future? Do I see a pattern here with code I have previously written and with code which my object clairvoyance tells me that I will one day write? Can I structure my present task into one of these patterns.
It is an annoying habit. Frequently, it is better not to have it. But when you find that every bit of code you write somehow falls into patterns and you refactor/realign those patterns until it covers most of your needs, you tend to get a feeling of satisfaction and accomplishment.
Problems begins to appear when a programmer gets delusional (compulsive obsessive object oriented disorder) and does not realise that there are exceptions to patterns and trying to over-manipulate patterns to cover more cases is wrong. It's like my childhood obsession with trying to cover a piece of bread completely with butter or jam spread every morning I had breakfast. That sometimes, it is just better to leave the object oriented perception behind and just perform the task at hand quick and dirty.
The accepted industrial adage of 80-20 might be a good measure. Using this adage in a different manner than it is normally perceived, we could say 80% of the time have an object oriented perception. 20% of the time - code it quick and dirty.
Be immersed by objects but eventually you have to resist its consuming you.
You probably have not done enough programming yet because if you have, you would see all the patterns that you had done and you will also begin to believe in patterns that you have yet to apply. When you begin to see such objectophrenia visions, it's time to be careful not to be consumed by them.
If you plan to use the script independently, then no. However if you plan to import it and reuse some of it, then yes. In the second case, it's best to write some classes providing the functionality that's required and then have a conditional run (if __name__=='__main__':) with code to execute the "script" version of the script.
My experience is that any purely procedural script longer than a few dozen lines becomes difficult to maintain. For one thing, if I'm setting or modifying a variable in one place and using it in another place, and those two places can't fit on a single screen, trouble will follow.
The answer, of course, is to tighten the scope and make the different parts of your application more encapsulated. OOP is one way to do that, and can be a useful way to model your environment. I like OOP, as I find I can mentally jump from thinking about how the inside of a particular object will work, to thinking about how the objects will work together, and I stay saner.
However, OOP is certainly not the only way to make your code better encapsulated; another approach would be a set of small, well-named functions with carefully defined inputs and outputs, and a master script that calls those functions as appropriate.
OOP is a tool to manage complexity in code, 50-250 lines of code are rarely complicated. Most scripts I have written are primarily procedural. So yes, for small scripts just go with procedural programming.
Note that for significantly complicated scripts OOP may be more relevant, but there is still not hard and fast rule that says use OOP for them. It is a matter of personal preference then.
Use the right tool for the right job. For small scripts that don't require complex data structures and algorithms, there is likely no use for object oriented concepts.
Am I missing something by not trying harder to use objects, or does OOP just not make a lot of sense for small scripts?
Objects buy you encapsulation and reuse (through inheritance). Neither is likely to be terribly useful when writing small scripts. When you have written a collection of similar scripts or you find yourself repeatedly changing your scripts, then maybe you should consider where objects might help.
In your case I'd say that OOP would be helpful only if it makes the scripts more readable and understandable. If not, you probably don't need to bother.
OOP is just another paradigm. A lot of problems can be solved using both procedural or OOP.
I use OOP when I see clear need of inheritance in the code i am writing, its easier to manage common behaviour and common attributes.
It sometimes makes it easy to understand, and manage. Even if the code is small.
Another benefit of OOP is to communicate intent (whether to other developers, managers, or yourself some point in the future). If the script is small enough where it can be fully communicated in a couple of sentences then OOP is probably not necessary, in my opinion.
Using OOP for few hundred lines of code rarely makes sense. But if your script is useful, it will probably grow rather quickly because new features will be added. If this is the case, it is better to start coding OOP way it will pay in the long run.
First of all - what do you mean by objects? In Python functions are objects and you're most likely using them. :)
If by objects you mean classes and instances thereof, then I would say something obvious: no, there is no reason to saying that using them is making your code better by itself. In small scripts there is not going to be any leverage coming from sophisticated OO design.
OOP is about what you get if you add polymorphism on top of modular programming.
The latter of both promotes low coupling, encapsulation, separation of responsibility and some other concepts, that usually produce code, that is short, expressive, maintainable, flexible, extensible, reusable and robust.
This is not so much a question about size, but about length of the software's life cycle. If you write any code, as short as it may be, as long as it is complex enough that you don't want to rewrite it, when your requirements change, it is important that it meets the aforementioned criteria.
OOP makes modular programming easier in that it has established solutions for implementing the concepts promoted by modular programming, and that polymorphism allows really low coupling through dependency injection.
I personally find it simpler to use OOP to achieve modularity (and reusability in particular), but I guess, that is a matter of habit.
To put it in one sentence. OOP will not help you in solving a given problem better, than procedural programming, but instead yields a solution, that is easier to apply to other problems.
It really depends on what the script is an what it's doing and how you think about the world.
Personally after a script has made it past 20-30 lines of code I can usually find a way that OOP makes more sense to me (especially in Python).
For instance, say I'm writing a script that parses a log file. Well, conceptually I can imagine this "log parser" machine... I can throw all these sheets of paper into it and it will sort them, chop parts out of some pages and paste them onto another and eventually hand me a nice report.
So then I start thinking, well, what does this parser do? Well, first off he's (yes, the parser is a he. I don't know how many of my programs are women, but this one is definitely a guy) going to read the pages, so I'll need a method called page reader. Then he's going to find all of the data referring to the new Frobnitz process we're using. Then he's going to move all the references about the Frobnitz process to appear next to the Easter Bunny graph. Ooh, so now I need a findeasterbunny method. After he's done that, then he's going to take the rest of the logs, remove every 3rd word, and reverse the order of the text. So I'll need a thirdwordremover and a textreversal method, too. So an empty shell class would look like so:
class LogParser(Object):
def __init__(self):
#do self stuff here
def pageReader(self):
#do the reading stuff here, probably call some of the other functions
def findFrobnitz(self):
pass
def findEasterBunny(self):
pass
def thirdWordRemover(self):
pass
def textReversal(self):
pass
That's a really contrived example, and honestly probably not a situation I'd use OOP for... but it really just depends on what's easiest for me to comprehend at that particular moment in time.
"Script" means "sequential" and "procedural". It's a definition.
All of the objects your script deals with are -- well -- objects. All programming involves objects. The objects already exist in the context in which you're writing your script.
Some languages allow you to clearly identify the objects. Some languages don't clearly identify the objects. The objects are always there. It's a question of whether the language makes it clear or obscure.
Since the objects are always there, I find it helps to use a language that allows clear identification of the objects, their attributes, methods and relationships. Even for short "scripts", I find that explicit objects and an OO language helps.
The point is this.
There's no useful distinction between "procedural", "script" and "OO".
It's merely a shift in emphasis. The objects are always there. The world is inherently object-oriented. The real question is "Do you use a language that makes the objects explicit?"
as someone who does a lot of scripts, if you get the idea that your code may at some point go beyond 250 line start to go oop. I use a lot of vba and vbscript and I would agree that anything under 100 lines is usually pretty straightforward and taking the time to plan a good oop design is just a waste.
That being said I have one script that came to about 500 line + and looking back on it, because i didn't do it oop it quickly turned into an unholy mess of spaghetti. so now anything over 200 lines I make sure i have a good oop plan ahead of time

Learn Go Or Improve My Python/Ruby Knowledge [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I was reading about Go, and I can see that it's very good and can be a language used by many developers in some months, but I want to decide a simple thing: Learn Go or improve my Python or Ruby knowledge?
Years developing with Python: 1
Years developing with Ruby: 0.3
If you're just looking to have fun and expand your horizons, then I'd learn Go, since you already know some Python.
If you're looking to improve as a developer, I'd personally recommend working on an actual project (using Python, as it's the language you have the most experience with):
This will take your (Python and general) programming skills to a whole new level
If you choose an interesting project, for example a semi-popular open source project, you'll even have some concrete result to show for your extra work. This will help your resume, help you meet other people interested in programming, etc.
I personally believe that spending the time you would have spent learning a new language by coding actual things you can use, is usually a net win (unless of course, like I said, you're just doing it for some fun recreation or relaxation).
In reality, you should do both; if it's what you want. For me though, out of the two, I'd only look at Python. I have no real interest in languages that are so new.
It depends on what your goals and your needs are.
If you're looking to develop your skills for a job, then go with Python or Ruby. You're unlikely to see Go show up in the workplace for quite some time (if ever) unless you're working at Google. (Even then it's questionable.)
If you want to have fun, do what you want. I think the best decider is, pick a project you want to work on and then choose the language that is best suited for that project.
Other things to consider:
Each language is suited to certain tasks. Go is compiled into machine code, whereas Python and Ruby run in interpreters. Go lends itself to somewhat lower level work. It's also good for concurrent tasks. Higher level tasks might be more suited for Python or Ruby.
Go is an experimental language that's likely to experience changes. These changes may be backward incompatible. If you learn it now, in 6 months or a year you may have to re-learn some of it because it's changed. That said, it can be fun to be a part of something that's on the bleeding edge. And if it does happen to become "the next big thing," you're in on the ground level.
How long have you been working with Python?
If it were me, I'd do my best to maybe get a working knowledge of Go (basic syntax, some familiarity with unique language features), and continue with Python as I normally would.
Eventually you might come up with a small project that Go seems suited for (or you can come up with one now!) and really dive into the language that way.
There's no reason to limit yourself to just one. :)
It's up to you. You should probably do both if you can, because that way you will have more tools on your metaphorical programmer's belt.
There are a number of things that I think are worth considering whenever I'm in a similar dilemma.
Is a new language (not just unfamiliar, but actually new, like Go) likely to catch on? (If so, it will become practically NECESSARY to learn it, rather than just a good idea.)
You will need to spend some time to learn the unfamiliar language. Will this time investment result in some sort of positive return? The obvious one here is development time (i.e., can you eventually get more done and get back the time you spent to learn it), but if the language is superior in other ways (runs faster or with less memory, is best for your particular problem domain) those might factor in too.
Will learning the unfamiliar language allow you to solve a relevant/important/urgent problem that cannot be solved with what you already know?
Unfortunately, none of us can tell you how to weigh each of these concerns. You'll need to think about it really carefully and come to the answer on your own.
First of all, it's a very very personal question, and my first recommendation will be , if you think so, try Go for one month or so, learning the basics, and then deciding... Each one has the mind fitted more to some particular languages than another...
I also would recommend keep using both Python and Ruby, if you're interested, you have enough experience to use them comfortably (I think), so the next months you could experience a great boost in your experience using them...
For an strict utilitarian point of view, learning Go extensively could be a risk move, but worthy if begins to being using and you're one of the very few people with some experience when everyone are just beginning to learn the syntax...
These two languages accomplish different goals. Go is only 20% slower than C. If you want crazy speed and easy parallelism, then learn Go. However, readability was not a design goal. Also, it has no exceptions. It can be used for real-time products though ...
IMO you should improve your Python knowledge. Python is a widely adopted language, whereas
Go is still at a very, very early stage and there's no reason to believe that it will become successful.
From a purely utilitarian perspective, you will get a lot more value from learning Python.
It's not easy to answer this without knowing how good your Python is, or what you do, or where you'd use Go. If you're looking for employment, I suspect Python is the way to go. I'd be surprised to find anyone is using Go for major projects at the moment (outside Google).
Note also that Go is by no means finalised. See here for the Go roadmap, and note the potential changes in the future. So you may be trying to hit a moving target currently.
Python is a available for most operating systems, it's generally accepted as a scriptin language, and it has matured to production quality.
Go is a research language that's only available in beta quality on Linux and OS X. Nowhere else. It's interesting from an intellectual point of view in that you can learn and apply a few concepts (typed channels combined with easy multitasking) that are otherwise difficult to use.
As for Go, you might perhaps take a look at AT&T's "Plan 9" operating system first. It comes with a programming language called "Aleph" with also is C-based, has channels and multitasking. Looks to me like Go is a reimplementation of Aleph on more main-stream operating systems.

Python networking library for a simple card game

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.

Python programming general questions

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.

Newbie teaching self python, what else should I be learning? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I'm a newbie to programming. I had 1 semester of computer science (we used java). I got an A in the course and was able to do everything assigned, however I'm not sure I really understood it. I ignored the text and learned by looking at sample programs and then trial and error. I was ahead of the class except for two guys who came in knowing java or another OOP language.
I'd like to learn Python. I'm also going to build a second PC from extra parts I have and use linux. Basically, I want to enhance my knowledge of computers. Thats my motivation.
Now on learning python are there any good programming theory books that would be useful? Or should I read up on more on how computers operate on the lowest levels? I don't think I know enough to ask the question I want.
I guess to make it simple, I am asking what should I know to make the most of learning python. This is not for a career. This is from a desire to know. I am no longer a computer science major (it also would not have any direct applications to my anticipated career.)
I'm not looking to learn in "30 days" or "1 week" or whatever. So, starting from a very basic level is fine with me.
Thanks in advance. I did a search and didn't quite find what I was looking for.
UPDATE: Thanks for all the great advice. I found this site at work and couldn't find it on my home computer, so I am just getting to read now.
My recommendation is always to start at the high level of abstraction. You don't need to know how logic gates work and how you can use them to build a CPU -- it's cool stuff, but it's cool stuff that makes a lot more sense once you've messed around at the higher levels. Python is therefore an excellent choice as a learning aid.
How to Think Like A Computer Scientist: Learning With Python is available on the Internet and is an excellent introduction to the high-level concepts that make computers go. And it's even Python-specific.
If you're looking to have your brain turned inside-out, SICP will do a good job of it. I don't recommend it as a first text, though; it's heavy going.
Both of these books are high-level. They won't teach you anything about the low-level details like memory structures or what a CPU actually does, but that's something I would reserve for later anyway.
D'A
Specifically for the Python part of your question I can highly recommend http://www.diveintopython3.net/ by Mark Pilgrim. That's free and pretty well structured.
Python is a nice choice, you will have fun!
http://www.pythonchallenge.com/
I think this Challenge is perfect to get in touch with major python strengths and there is a nice forum with a lot of interessting Python Threads for each Level.
A lot of this depends on what your overall goal is for learning Python. Are you viewing it as learning a second language or getting a better understanding of computers and how to effectively use a programming language?
From what it sounds like you want to gain a better understanding about computers and be a better programmer. Learning a new languages such as Python will probably not help you in this respect. I still recommend learning Python if you're interested, but once you have learned one programming language, much of learning a new language is getting familiar with the syntax and data types (usually).
You had mentioned you were unsure about understanding the material in the class you took. If you feel you don't understand fundamental concepts (such as loops, classes, etc), then learning Python will help your understanding of programming as most books/guides revisit these concepts (Learning Python, 3rd Edition should help with this). If you understand these concepts, but you are unsure of how to apply these concepts, then my recommendation would be to learn about data structures and common algorithms (e.g. sorting, searching, etc).
Speaking from personal experience, I didn't know how to apply what I learned from the introductory programming class to personal programming projects. Learning about data structures from a class helped solidify those concepts I had previously learned by providing algorithms/data structures that build off of this previous knowledge. This class also allowed me to think differently about problems in terms of using these data structures.
To learn about the different types of data structures, see: http://en.wikipedia.org/wiki/List_of_data_structures. Usually, each data structure is useful for a specific purpose (e.g. binary search trees are good for searching sorted information). Unfortunately, I don't have any book recommendations (our class didn't use a book). Googling "Data Structures" should be a good starting point.
Data structures also got me to think about how efficient an implementation is. The "complexity" of an algorithm determines how long a given piece of code takes to run. This makes it easy to compare other implementations and determine which is better.
I would also like to comment that when it comes to learning computer concepts, the best way to learn is by doing. A book/class can only explain so much, and the rest you have to learn on your own. Each person learns differently, and programming is a way of taking the material you read about and think about it in a way that is best understood by you.
I hope I answered your question. At this point, you don't really need to worry about the underlying hardware. This is useful to know if you plan on doing this as a career (which you aren't), or want to make optimizations specific to the hardware you're running on (in which case, you wouldn't want to use Python). Python is a good choice to learn about data structures as it implements a lot of them for you, but it's important to know what they are used for.
If you are still in school, take a data structures class and see what you think of it. If you like it, I'd advise reconsidering the role of programming/CS in your career. You don't have to major in it, but consider a minor or at least a position that makes use of these skills you are learning. I say this because despite this not being your major, you are interested in understanding how a computer works and taking initiatives such as learning Python, building your own computer, and installing Linux.
If you have any further questions, feel free to ask. Good luck!
Python is a high-level language, so it wouldn't give you much direct benefit to learn how computers operate at the lowest levels.
Don't get me wrong - I do strongly believe that the low-level operation of a computer, e.g. assembly language and hardware, is something that every good programmer should be familiar with, because it does help you program more effectively in whatever language you are using, high-level or low-level. But it won't make much of a difference in your Python coding until you've gotten quite a bit of experience. If you're just starting out with Python, I would suggest staying away from the low-level operation of computers and concentrating on the basics of Python for now. Once you're comfortable with that, you can move on to something like C and then it might be appropriate to start looking at some lower-level stuff.
As for what you should know... not much, I guess. Python is a great language to start out programming in. It keeps simple things simple but it's rich enough to let you work your way up to a high level of complexity. I'd suggest probably looking at a tutorial; the one I happen to know is on the Python website, but I'm not claiming it's necessarily the best one for you. A Google search should give you plenty to get started with.
I started Python (as my first programming language) few months ago. I would recommend Learning Python, by Mark Lutz to begin with. But keep in mind that the key to learn well is to be open-minded, patient and willing to work and look up for things you don't understand.
Have fun!
I would suggest looking at the online book at http://www.diveintopython.org/ to learn python.
As for python projects, I would try learning the Django Framework. It is a framework for building web applications. They have a great tutorial for getting started with it. This would also give you experience building a webserver on a Linux box.
enhance my knowledge of computers
Well, what do you exactly mean by that? Python, or any other high level language, are designed to actually hide all the nasty details. That's one of the reasons, why it's apt for non-pros like (e.g. scientist).
If you want to know how stuff actually work, you should learn pure C. But then again, if you're not planning to have any career related to SC, there's not much point to it. Learn some more advanced algorithms and data structures instead. That'll result you more interesting, useful and is platform- and language-agnostic.
Short answer: all of them
Long answer:
Learning your first language is always a challenge, and after your Java experience, a lot of other languages will seem a lot simpler. That said, the real challenge in learning programming languages is learning when to use a particular language -- you can find decent docs for whatever you choose when the time comes.
As a concrete start, hop over to wikipedia and browse their categorical list of programming languages, click on all of the names you've ever heard (and anything else that catches your eye) and if the article has a code example, give it a minute or two to sink in (the rest of the article will help, of course). The point here is not to master every single language (which is (1) pointless and (2) impossible), but to get a handle on what is out there. For any language, there is a handful of other languages like it, and if you can at least read one language in most of those categories, you will have mastered a fairly large chunk of the programming universe. When a new project comes up, and something about it reminds you of some language you found, you can just learn that language as part of doing the project. It may sound like a lot of work, but after, say, your fifth big language, you completely lose count and just accidentally learn new ones all the time without noticing.
When you stop relating to one language as your home-language, you'll be able to learn from examples in other languages even if you've never programmed in them. Personally, I've only written a few Haskell programs, but being able to read Haskell has exposed me to a lot of ideas that I could recycle in more practical Scala and Python programs (oh yeah, after you learn Python, give Scala a browse and you'll probably never use Java again)
Even finding the best language for the job isn't the whole story. Having a lot of tools in your toolbox lets you throw together amazing stuff in short amounts of time by writing each piece of your project in the easiest language your could. This may not be appropriate for all projects, but, boy, can you make some impressive demos.
It takes many years to get to the point where no programming language is totally foreign (or at least foreign for more than a day of hacking), but I think it is a very healthy and realistic long-term plan to attempt to conquer a representative sample of each rough category. Good luck!
Since Python wasn't my first language, I found the Python Cookbook helpful for learning
What Python was capable of
The idiomatic, of "pythonic," way to do something.
Programming language teaching has always been associated with a cliche statement while learning. "Write programs to learn programming". I too would suggest the same.
If you are going to start from basics. This is of course, the most suggested starting point. It is lengthy, but it is worth all the time. http://www.diveintopython.org/
Because you are into some Java, this might be even better for you. http://www.swaroopch.com/notes/Python. Start either python 2.x or 3.0. Me personally am a fan of python 3. But for a starter it could be hard to get samples, and references to programs online. So for you 2.x might be better. But I leave it upto you.
Like I started "Write programs..". You can start here.
http://www.spoj.pl/ - a programming challenges site, where you can choose from a wide variety of topics, mostly algorithms and has huge question database. Of course the choice of programming languages is upto you.
http://projecteuler.net/ - a mathematical questions site, here you just have to submit an answer, cheating is allowed here, so be free to borrow logic from others, but try writing the program yourself.
After you think you have gained sufficient proficiency in python, you can try recipes in this book python cookbook http://www.amazon.com/Python-Cookbook-Alex-Martelli/dp/0596007973.
For application development, after you think you can handle it, start on wxPython or PyQt. I personally would suggest PyQt. It is responsive, fast, and has decent development cycle, I have not used WxPython for long, but few programs I wrote, long back, didn't feel so great. Yet again, its upto you.

Categories