|
-
Nov 27th, 2001, 08:01 PM
#1
Thread Starter
Fanatic Member
Python?
What's so good about Python?

prog_tom
JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
http://physics.sviesoft.com/forum
-
Nov 27th, 2001, 08:11 PM
#2
Frenzied Member
what is python
-
Nov 27th, 2001, 09:10 PM
#3
It's an embeddable scripting language. I found no use for it whatsoever.
Z.
-
Nov 27th, 2001, 09:24 PM
#4
-
Nov 28th, 2001, 12:16 PM
#5
Black Cat
Ruby is an OO scripting langauge that's supposed to be a better Perl than Perl. I intend to play with that or Python eventually...
Josh
Get these: Mozilla Opera OpenBSD
I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.
-
Nov 28th, 2001, 01:24 PM
#6
I heard once that Python has a special data type that lets you use numbers potentially thousands of bits long! So you could evaluate Pi to a lot of decimal places, for instance.
That's the only interesting thing about python so I hear! 
I'll stick to VC++ or VB (imho, the nicest bits of kit that MS have ever produced).
-
Nov 28th, 2001, 08:10 PM
#7
Fanatic Member
It's used by scientists because you can have variables whose size/presicion is limited only by the amount of memory your computer has, so they can calculate π to millions of decimal places.
Alcohol & calculus don't mix.
Never drink & derive.
-
Nov 28th, 2001, 08:45 PM
#8
Frenzied Member
I spend about 90% of my time at work programming in Python, so I reckon I'm probably qualified to answer this a little better than most people 
It is an embedable scripting language, as Zaei says... although that's just one side of the things you can do with it.
You can embed Python into a C/C++ application, which essentially just passes your Python commands to the Python interpeter. It's not hard to do, and has been used in a couple of commercial games, such as Severance: Blade of Darkness (published by Codemasters). You can also extend Python with modules written in C/C++. So it is both embeddable and extendable.
Python is also very much an object-oriented language, contrary to what some people in this thread seem to think.
The main reason people who use Python use it is that it's pretty easy. It's an interpreted language so it doesn't cause catastrophic errors when things go wrong but instead gives you a useful traceback, containing information about where and when the error happened and how the flow of the program arrived there.
There are many different modules that you can import to do things that are pretty complicated in many other languages. For instance, to get a web page in code: (hash signs are comments in Python)
Code:
#urllib is a module with FTP/HTTP utilities in it
import urllib
#now urllib is imported, we can use stuff that's in it
#get a page and assign it to a variable
vbforumshomepage = urllib.urlopen("http://www.vbforums.com")
#urlopen returns a file object so vbforumshomepage is a file object
#print the HTML for the page
#file objects have a read method which returns their contents
print vbforumshomepage.read()
That's basically 2 lines of code, not including importing the module containing the utilities (a bit like a #include in C/C++).
As Wynd says, it's often used for scientific purposes because it's very good for prototyping mathematical models and has native support for theoretically infinitely long numbers and for complex numbers. It gets a fair bit slower when you're dealing with numbers that aren't in the usual 32-bit range, but it's easy to do if you don't mind the performance hit. You'd get the same performance hit in any other language anyway. It's also platform-independant, so a researcher can get a number-crunching app working on their laptop/desktop, then set it running on a big Solaris server (or whatever) without any code changes.
It just generally has handy built-in types, like lists and mappings. Very useful stuff. Humans basically think in terms of mappings, so having them built-in makes programming easier. I think there are STL map classes in C++ but I haven't really investigated them much.
If you are interested in using something like Python as an embedded scripting language for games, I have heard some good things about a language called Lua (www.lua.org) which is similar to Python. Baldur's Gate was scripted in Lua.
Also, if you're familiar with C/C++, Python should be very easy to pick up since it has similar styles.
My only gripe with Python at the moment (currently stable version 2.1 I believe) is that the typing is slightly too loose. It's fine with the built-in types, but class typing is a little awkward.
Anyway, if anyone has any questions about Python, I can probably answer them but if they stump me I have some very experienced people available to me that I can ask.
Harry.
"From one thing, know ten thousand things."
-
Nov 28th, 2001, 10:12 PM
#9
Ill bet my scripting language beats out Python in speed =).
Sounds pretty interesting, Harry. Thanks for all of the info. I downloaded it once, but never really got into it, no time (that seems to happen a lot, these days =).
Z.
-
Nov 29th, 2001, 05:24 AM
#10
Frenzied Member
Well Zaei, if your scripting language does what Python does better and faster, lets see it
Harry.
"From one thing, know ten thousand things."
-
Nov 29th, 2001, 07:39 AM
#11
I did say speed =).
Its a psudo ASM thing (twice as fast as VB =). I would like to get around to adding structs, and perhaps classes, but i dont have the time at the moment.
Z.
-
Nov 29th, 2001, 08:18 AM
#12
transcendental analytic
it's pseudo, not psudo Zaei May I ask you how you perform the speed tests, because it's probably biased, it also depends on what exactly is performed and Python/VB probably has wide range of capabilities. Pretty much your tradeoff of performance is the introduction of a higher paradigm such as OOP, and to minimize it you have to optimize the compilation which isn't possible for a scripted language.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 29th, 2001, 08:39 AM
#13
A for loop, performed 1000 times with this code:
Code:
x = 1
x = x + 2
debug.print x
x = x -1
debug.print x
x = 10
x = x * 2
debug.print x
x = x / 2
debug.print x
the C++ version
Code:
x = 1;
x = x + 1; // might have been x += 1, but I dont remember
cout << x << endl;
x = x - 1;
cout << x << endl;
x = 10;
x = x * 2;
cout << x << endl;
x = x / 2;
cout << x << endl;
my version:
Code:
mov aa 1
add aa 2
push aa
int 0 // same as "cout << x << endl;"
sub aa 1
push aa
int 0
mov aa 10
mul aa 2
push aa
int 0
div aa 2
push aa
int 0
The only place it might be biased is that my script is contained inside of a C++ for loop, but it also includes the need to Reset every execution. So it is a bit biased =).
And kedaman.... everyone knows that I cant type =).
When I get home, I will rewrite the test to use a scripted for loop (maybe I should change the mul aa 2 to a shl aa 1 for some more speed =). We shall see =).
Z.
-
Nov 29th, 2001, 08:42 AM
#14
Oh, and it IS compiled, kedaman =). Thats what makes it so fast. The only interpretation that needs to be done is to determine if the second set of data to an opcode is a variable or actual data =).
Z.
-
Nov 29th, 2001, 08:55 AM
#15
transcendental analytic
debug.print lol, cout, nah, skip those, they're just hogging up all the performance flooding the actual results, do you compile to 80x86 or bytecode or something else?
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 29th, 2001, 10:42 AM
#16
Frenzied Member
Script wars, yeah! 
Are you actually including those debug.print statements in your code Zaei? If so, I'm surprised it's only 2 times as fast. Take out all the input/output and leave it to the end.
Harry.
"From one thing, know ten thousand things."
-
Nov 29th, 2001, 03:39 PM
#17
Alright. I will create a new test. Gimme a few minutes =).
Z.
-
Nov 29th, 2001, 03:53 PM
#18
Uhhh... GetTickCount() isnt accurate enough to compare them. Both return 0ms =). Here is the test code:
Code:
Dim i As Long
Dim x As Long
Dim y As Long
For i = 0 To 10000
x = 10
x = x * 2
x = x / 2
x = x + 1
x = x - 3
y = 10
x = x + y
y = x
Next i
Code:
sloop:
mov aa 10
mul aa 2
div aa 2
add aa 1
sub aa 3
mov ac 10
add aa ac
mov ac aa
inc ab
cmp ab 10000
jl sloop
Z.
-
Nov 29th, 2001, 03:58 PM
#19
Frenzied Member
Increase the number of iterations then There is a more accurate counter too, I just don't remember the name. It works in microseconds I think.
Harry.
"From one thing, know ten thousand things."
-
Nov 29th, 2001, 04:00 PM
#20
Frenzied Member
How is your version significantly different from ASM?
Harry.
"From one thing, know ten thousand things."
-
Nov 29th, 2001, 04:17 PM
#21
Different bytecode, as well as some different opcodes (alloc, and la for arrays, etc).
Well, as it turned out, I screwed up the tests. I wasnt actually executing the script, simply loading it.
The really terrible part is that, when I fixed this little error, and compiled back to release mode, i get a VERY consistant 0ms exec time, for 1 million iterations. Im pretty sure that it does in fact execute the script, but I am making sure (even _I_ can hardly believe that!). Check back in a sec!
Z.
-
Nov 29th, 2001, 04:42 PM
#22
Arg. It still want executing. 1000ms for 100000 iterations, as opposed to vb, 100 =(.
Looks like I have some optimising to do. Have to shave off 900 ms =).
At least my 2 times faster then VB with Output still stands =).
Z.
-
Nov 29th, 2001, 04:58 PM
#23
Oh, it also has support for functions:
Code:
function hello()
ret
call hello
Z.
-
Nov 29th, 2001, 05:02 PM
#24
transcendental analytic
doesn't matter, assembly sucks, no style
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 29th, 2001, 05:07 PM
#25
::SLICE:: There goes about 870 ms. Its down to 120 - 130ms.
It's a different style, kedaman =). Besides, I gave it just a touch of style with function calls:
Code:
call main
int 0
end
function main()
mov aa 10
push aa
pop ab
mul ab 10
div ab 3
inc aa
inc ab
add aa ab
push aa
ret
Z.
-
Nov 29th, 2001, 05:09 PM
#26
Oh, in regards to all of the two letter variable names.... Its a speed thing. Each letter is one byte of a WORD that makes up a variable index in the program starting with aa, which is 0. I havent gotten around to adding nicer variable names into my preprocessor yet.
Z.
-
Nov 29th, 2001, 05:37 PM
#27
Frenzied Member
So uhh... why use your script instead of just ASM? Sorry, I thought one of the main ideas of a scripting language was that it was easy to write. As in high-level.
Harry.
"From one thing, know ten thousand things."
-
Nov 29th, 2001, 05:42 PM
#28
transcendental analytic
I thought it was portability and yeah without OOP a scripting language is pretty useless.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 29th, 2001, 05:46 PM
#29
Its a component of my game engine. The design from the very beginning was to make it as modular as possible (the actual scripting module is standalone). Each script compiles into an Object, where each Opcode/lhs/rhs combo is 64 bits, plus function names and locations (so you can call script functions from engine code. This allows me to create Objects whose behaviors exist only as function pointers in some library or another, while scripts act as Builders, to construct a unique object. This would allow new game content (new units, weapons, etc) to be released, and plugged directly into the game.
Also, since the scripting language is at the lowest level, an HLL could be built right on top of it. Nothing limits it to pseudo(kedaman =) ASM.
Z.
-
Nov 29th, 2001, 05:47 PM
#30
Objects are an addition that I would like to add at some point. At the moment, though, it fulfills it's purpose nicely =).
Z.
-
Nov 29th, 2001, 05:49 PM
#31
And it is portable... the only thing that isn't really is the compiler (written in VB (oh the irony!) =).
Z.
-
Nov 29th, 2001, 07:13 PM
#32
transcendental analytic
You could write the compiler in gwbasic if you want, I don't care, probably the only thing that matters is the amount of hidden bugs inside the compiler when doing so. If i'm going to use any scripting for runtime purpose it's going to be python, but I hardly think so, because C++ is the ultimate tool for me, even for runtime scripting =) =) =) =) =)
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 30th, 2001, 01:37 PM
#33
Just wondering: who uses Python the most, amateur programmers or professionals, is it a respected language yet (it's quite new isnt it?)?
Is it worth my while getting involved with it (I'm an unemployed programmer trying to diversify into other languages, like C)?
-
Nov 30th, 2001, 08:49 PM
#34
Frenzied Member
Well to be honest there probably aren't a great many places that use Python, not because it's not useful to them but because it doesn't have as much support as something in a comparable position like Java or Perl (both similar in ways to Python). It's not all that new. If you want to know how long it's been around, visit www.python.org.
If you're a programmer looking for useful languages to learn and you don't know C already then I would definitely recommend you learn C/C++. It's really an excellent way to get a better feel for the way the computer works at nearly the lowest level, which will ultimately (IMO) make you a better programmer overall.
Python is really a great, flexible high-level language, but unless you are lucky enough to get to work with an open-minded organisation that really looks at all the technologies available seriously (ie not a M$ shop), you will probably not get to use it much.
If you want to field questions like this to a group of Python programmers, try the main Python IRC channel - irc.openprojects.net #python. I'm in there fairly often, along with #zope which also runs on that server, as HarryW.
Harry.
"From one thing, know ten thousand things."
-
Dec 1st, 2001, 11:53 AM
#35
Is there any (easy) way to embed Java into another (non-Java) application?
Z.
-
Dec 1st, 2001, 08:47 PM
#36
Frenzied Member
I don't really have any idea. You're probably better off asking that in the Java forum
Harry.
"From one thing, know ten thousand things."
-
Dec 1st, 2001, 09:46 PM
#37
Its just curiosity =). Both Java and Python are scripting languages, so I thought id just ask =).
Z.
-
Dec 2nd, 2001, 07:20 PM
#38
Frenzied Member
Well, although the official Python project is written in C, there is another ongoing project to implement it in Java (called Jython I think), and that's got to be embeddable, so it must be possible.
Harry.
"From one thing, know ten thousand things."
-
Dec 3rd, 2001, 06:26 PM
#39
Monday Morning Lunatic
For whoever asked about accurate timers...
The Pentium introduced the RTDSC (or is it RDTSC?) instruction that gets the number of clock cycles (i.e. the time is dependent on processor speed) since the processor was initialised (I think this is only on power-up, but may be reset on a hard system reset).
Either way, most assemblers won't support it MSVC lets you use the _emit pseudoinstruction that DIRECTLY includes the bytes you specify into the output object file.
I did post an example on the forum...
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Dec 4th, 2001, 01:35 PM
#40
Accurate timers...
I was browsing the DJGPP C++ compiler's help files a few weeks ago and it said that it has a function that is accurate to +/- 840 nanoseconds (8.4*10^-9 seconds) !
I don't know if anyone can verify this, but its interesting anyway.
Any thoughts?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|