Jump to content

Python!


In My Memory

Recommended Posts

CapnRefsmmat suggested that I should learn Python, so I downloaded it last night and I do some very very simple things with it now. I learning it for fun, to increase my NQ (nerd quotient), and maybe to help me out in my work.

 

So I have some questions:

 

- Is it possible to force variable declaration? Forced declaration is automatic in C++, and it is optional in VB, but I've looked through the python handbooks and online and I havent seen anything.

 

- What can I do with Python? Does it support bitwise operations like rotate-left, right-shift, and other bitwise arithmatic? Not that I really need it, but will support the creation of 3D graphs or shapes? Is it possible to write an IMM-bot that will respond to posts on SFN when I'm not around?

 

- Would you like to share some python examples :) So far, heres my most successful program:

print 'cat'

It works like a charm :P

 

 

And if you have any other pearls of wisdom you'd like to share to a newbie programmer, share them! :)

Link to comment
Share on other sites

I´ve used Python a few years back and I found some old code snippet that might prove usefull to help you a bit:

 

"""
Create a fake "spiral galaxy"
"""
from scipy.xplt import *

# STEERING CONSTANTS
size = 150           # Size of the matrix

# Part of the complex plane to be shown
rMin, rMax = -0.578, -0.563
iMin, iMax = -0.569, -0.555

# => Stepsizes
dr, di = (rMax-rMin)/size, (iMax-iMin)/size

def RecursionDepth(c):
   z = 0.0+0.0j
   d = 0
   while abs(z)<2:
       z = z**2+c
       d +=1
       if (d>200):
           return d
    #   print z, d, abs(z), c

   return d

# Create Matrix
M = zeros((size, size))

re = rMin
for i in xrange(size):
   im = iMin
   for j in xrange(size):
       z = re+im*1j
       M[i, j] = RecursionDepth(z)
       im += di
   re += dr

window(1)
palette("heat.gp")
M[0,0] = 300; pli(M)
raw_input()
winkill(1)

I dunno if the scipy-package (scipy stands for "scientific python", I think) is widely used (i.e. if it´s in the distribution you downloaded) but one of your questions might be answered by above code even if you don´t have it:

- You can set the type of a variable by giving it an appropriate value. So if you want an integer to equal one, you assign "x = 1", if it´s supposed to be a floating point variable, you assign "x = 1.0" and if it´s supposed to be a complex, you assign "x = 1.0+0.0j". Not completely sure if that´s what you wanted, though.

 

For the other question:

- Afaik, Python is a comeplete OOP programming language so you should be able to do anything you can do with other programming languages. I think even the 3D-engine Ogre3D has a Python version. I really enjoyed writing programs in Python and I think it´s quite a good language for a beginner (although I don´t know whether you are a beginner or not).

Link to comment
Share on other sites

The Pythonistas sure seem to be doing a bang up job of recruiting people to learn Python as their first language.

 

I wouldn't ever recommend it as such, especially considering its syntax is completely different from any other language on earth, but I guess that's because I'm a Rails zealot who doesn't know Python and I really get a kick out of how much time the Pythonistas spent trying to abstract away common patterns in web development only to get thoroughly shown up by Rails. So I enjoy mocking Python in total ignorance, knowing that deep down Ruby and Python are basically the same...

 

Anyway, sorry for this totally uninformative contribution to your thread there IMM... I guess all I can say is that Python isn't that bad of a language to start out with; there are plenty that are much much worse.

 

What can I do with Python? Does it support bitwise operations like rotate-left, right-shift, and other bitwise arithmatic? Not that I really need it, but will support the creation of 3D graphs or shapes? Is it possible to write an IMM-bot that will respond to posts on SFN when I'm not around?

 

I'm certainly not going to be an authoritative source on any of this, but I think you can safely assume the answers to all these questions (save for the first) is "Yes"

Link to comment
Share on other sites

Have you been amazed by the progress bar in Fedora Core installation.

 

I heard that the progress bar in Linux installations that shows the amt of OS installed, time remaining, etc was developed in Python :)

 

Its a breeze to learn... and it a programmer quoted in dobbs journal that his 10 y.o. daughter was able to draw a sine curve in python. :)

Link to comment
Share on other sites

From what I can see, Python has the standard C-style bitwise operators (i.e. <<, >> for shifting, | & ^ for OR, AND and XOR). If you're interested in 3D programming, there's the Visualization Toolkit (VTK) which is a relatively easy way of displaying 3D stuff. Either that, or you can just use a Python OpenGL wrapper.

 

Basically there's a lot of bindings out there for Python as it seems to be one of the languages of choice over there. A lot of the cooler things like GStreamer have bindings, as well as GTK, QT and a whole host of other things. Personally, I don't particularly like the language, although I am going to learn it since I'm taking a module which is partially based off of Python in the Autumn term. But it seems to be a handy and easy to learn language, so go for it :D

Link to comment
Share on other sites

I tried learning python a month back.

 

Take it from me - Its the number 1 programming language for newbies - so you've made a wise choice. (It took me ages to realise this).

 

Its so easy to get into (I was declaring and using functions in 2 days).

 

You can get a good book about starting python here which takes you all the way to the object orientated concepts:

http://ibiblio.org/obp/thinkCS/python.php

 

The website (python.org) also has had a much needed makeover and there are some interesting articles on how python has been used in industry (NASA is using it - which is personally appealing).

 

However - it is still considered a second-rate language in the sense that it cannot compete with C++ and java and is frequently noted as a "glue" language or a secondary/supportive language which is annoying because I would like it to be mainstream (call me pythonistas if you like).

 

I think what python needs is better resources and a free professional looking IDE (not pywin because that is just annoying at times). Things are picking up now - I'll definitely use python (if I ever decide to do a software project).

 

well

that's my 2 <insert currency>

Link to comment
Share on other sites

If you want to do good 3D rendering, I recommend Ogre3D (http://www.ogre3d.org) which is an object oriented C++ library of really good design and quality.

 

They do have Python addOn, http://www.ogre3d.org/phpBB2addons/viewforum.php?f=3

 

I've only used C++ so I don't know how easy the python element is. The API itself though is the easiest lib I've ever worked with.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.