Page 1 of 2 12 LastLast
Results 1 to 40 of 42

Thread: Python?

  1. #1

    Thread Starter
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810

    Post Python?

    What's so good about Python?

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  2. #2
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    what is python

  3. #3
    Zaei
    Guest
    It's an embeddable scripting language. I found no use for it whatsoever.

    Z.

  4. #4
    Apparently it is a good language to start learning, but I say BS to that. Just start with something strictly OO, such as C++ or Java. VB is not a good first language.

  5. #5
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    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.

  6. #6
    wossname
    Guest
    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).

  7. #7
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    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.

  8. #8
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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."

  9. #9
    Zaei
    Guest
    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.

  10. #10
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Well Zaei, if your scripting language does what Python does better and faster, lets see it
    Harry.

    "From one thing, know ten thousand things."

  11. #11
    Zaei
    Guest
    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.

  12. #12
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  13. #13
    Zaei
    Guest
    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.

  14. #14
    Zaei
    Guest
    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.

  15. #15
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  16. #16
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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."

  17. #17
    Zaei
    Guest
    Alright. I will create a new test. Gimme a few minutes =).

    Z.

  18. #18
    Zaei
    Guest
    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.

  19. #19
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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."

  20. #20
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    How is your version significantly different from ASM?
    Harry.

    "From one thing, know ten thousand things."

  21. #21
    Zaei
    Guest
    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.

  22. #22
    Zaei
    Guest
    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.

  23. #23
    Zaei
    Guest
    Oh, it also has support for functions:
    Code:
    function hello()
    
    
    ret
    
    call hello

    Z.

  24. #24
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  25. #25
    Zaei
    Guest
    ::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.

  26. #26
    Zaei
    Guest
    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.

  27. #27
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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."

  28. #28
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  29. #29
    Zaei
    Guest
    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.

  30. #30
    Zaei
    Guest
    Objects are an addition that I would like to add at some point. At the moment, though, it fulfills it's purpose nicely =).

    Z.

  31. #31
    Zaei
    Guest
    And it is portable... the only thing that isn't really is the compiler (written in VB (oh the irony!) =).

    Z.

  32. #32
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  33. #33
    wossname
    Guest
    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)?

  34. #34
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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."

  35. #35
    Zaei
    Guest
    Is there any (easy) way to embed Java into another (non-Java) application?

    Z.

  36. #36
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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."

  37. #37
    Zaei
    Guest
    Its just curiosity =). Both Java and Python are scripting languages, so I thought id just ask =).

    Z.

  38. #38
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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."

  39. #39
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  40. #40
    wossname
    Guest
    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?

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width