How to program in Python + Paste Code for review/help

The S&M crowd is getting naughty with the game files.

Re: If you want to learn how to program in Python...

Postby Grumblesaur » Wed Apr 06, 2016 10:59 pm

Additionally,



Change
Code: Select all
collapsed[temp['text']] = True if (temp['open'] == 1 or temp['open'] == 'true') else False

to
Code: Select all
collapsed[temp['text']] = temp['open'] == 1 or temp['open'] == 'true'

since the `or` keyword will evaluate to a boolean value from its operands, which are expressions that also evaluate to boolean.
User avatar
Grumblesaur
Moderator
 
Posts: 1992
Joined: Sun Dec 02, 2012 8:57 pm
Location: Spotsylvania, VA, USA

Re: If you want to learn how to program in Python...

Postby Victor Tombs » Wed Apr 06, 2016 11:43 pm

The last time I had a rubbing of shoulders with Python was with Wrye Bash during my Oblivion days. :oops: Good to know the coding fraternity are still using it. :)
Victor Tombs
Elder Council Member
 
Posts: 7181
Joined: Tue Dec 25, 2012 6:58 pm

Re: If you want to learn how to program in Python...

Postby Flatfingers » Thu Apr 07, 2016 12:57 am

Leaping foolishly into the fray.... :lol:

1. Real string manipulation is done in SNOBOL. Or would be, if anyone still used SNOBOL.

2. Java's not bad at string manipulation, but -- last I checked -- the switch() function still didn't know how to process strings. It only accepts numeric inputs. That's just head-shakingly bizarre to me.

3. That said, until recently Java was actually a pretty pleasant and powerful language for writing self-contained applications. Native compilers have pretty much eliminated any seriousness to claims that it's "too slow" (which its early bytecode versions could be, depending on the application).

4. Unfortunately, after Sun sold out to Oracle, a company (I speak here solely as a private individual) I despise, Oracle has made the last couple of versions of Java increasingly baroque, with countless bizarre little encrustations that complicate learning and using it. That's a shame.

5. Unless you need blazing speed, there's not much you can't do with JavaScript + CSS + HTML5. I recently finished a game (for Mrs. Flatfingers) that does some fairly intense number-crunching to generate complex logic puzzles. This part of the game actually runs slightly faster than the original compiled version of the game. And the cross-browser support is real -- both that game and the one I'm working on now understand how to adapt to and run on all of the major browsers. So, as a general observation, even an interpreted scripting language doesn't have to be bad.

6. Because I'm on a roll, I will add a gratuitous personal observation that while an interpreted scripting language doesn't have to be bad, it certainly can be made bad by infecting it with garbage like jQuery. jQuery looks like a Perl hacker decided to troll JavaScript users, and they still haven't gotten the joke. jQuery DOES NOT LOOK LIKE JAVASCRIPT. For all its "features" (all of which can be done with relative ease in straight-up JavaScript), it changes the "feel" of JavaScript -- learning JavaScript won't help you understand jQuery. If other people like it, OK. I don't.

7. I've used IDEs since before Visual Studio was a thing, and I've never yet found one I like. Every last stinkin' one of them insists on injecting junk into my nice clean code, and tries to force me to organize my code according to its beliefs as to how programs "should be" written. No, thank you. I will stick with my text-editor-of-choice (Zeus, a modern version of the incredibly intuitive -- and moddable! -- BRIEF text editor), which guarantees that the only top-level code that might generate a bug is mine. It's hard enough getting my own code to work; I have zero interest in also debugging whatever cruft some IDE slips into my project.

8. I appreciate the references to Python learning resources. I'm confident that, after just a few short days of study, I will find something to dislike about this language, too. ;) (Beyond the indentation-as-scope-control silliness. :silent: )

Grumble away. :)
User avatar
Flatfingers
Vice Admiral
 
Posts: 4530
Joined: Sat Nov 24, 2012 12:45 am

Re: If you want to learn how to program in Python...

Postby Dinosawer » Thu Apr 07, 2016 1:41 am

Flatfingers wrote: Every last stinkin' one of them insists on injecting junk into my nice clean code

I've never had any IDE do that :wtf:

Flatfingers wrote:
and tries to force me to organize my code according to its beliefs as to how programs "should be" written.

And only 1 IDE who did that and that notification was very easy to turn off.

What kind of IDE's are you using? :ghost:


Victor Tombs wrote:The last time I had a rubbing of shoulders with Python was with Wrye Bash during my Oblivion days. :oops: Good to know the coding fraternity are still using it. :)

Well, the reveal that Python is the new LTSL made a few people here eager to learn it :mrgreen:
Warning: do not ask about physics unless you really want to know about physics.
The LT IRC / Alternate link || The REKT Wiki || PUDDING
Image
User avatar
Dinosawer
Admiral
 
Posts: 5808
Joined: Fri May 09, 2014 1:08 pm
Location: Belgium

Re: If you want to learn how to program in Python...

Postby FormalMoss » Thu Apr 07, 2016 6:11 am

Dinosawer wrote:ARISE THREAD AND REVEL IN YOUR NEW-FOUND USEFULNESS :ghost:



Other than that, myself and several other people who regularly hang out on the Limit Theory IRC are Python programmers and are more than willing to help you if you have a problem, so feel free to drop by. ;)


Thanks Dino, I have updated the landing page for handy resources.

Flatfingers, can you provide links for IDEs please?

I currently use Enthought Canopy for Python, and CodeLite for IDE.
YAY PYTHON \o/

In Josh We Trust
-=326.3827=-


User avatar
FormalMoss
Captain
 
Posts: 978
Joined: Fri Jun 06, 2014 8:06 am

Re: How to program in Python + Paste Code for review/help

Postby JoshParnell » Thu Apr 07, 2016 11:00 am

It's really essential that the distinction between language and implementation / execution model be made. This is especially true in the case of so-called 'interpreted' languages, since, well, it's really fundamentally wrong to call a language 'interpreted.' A language is a specification of a grammar, semantics, and the precise functionality that those semantics should provide. 'Interpreted' refers to an execution model of a piece of code, whereby the 'code' that's being interpreted is not run as native machine code, but rather by proxy through a bytecode engine, which generally is native machine code (at least, a bytecode engine is usually the form taken by interpreters, and is in the case of Python).

However, there is nothing preventing the static compilation of a language like Python. And I'm not even talking about Cython or required static typing, I'm saying that there's nothing preventing the static compilation of a dynamically-typed program. It's hard but feasible (and yes, there is always a performance hit for dynamic-typing, but it's nothing compared to the performance hit of running through an interpreter). OTOH if we restrict to static typing, it's downright easy to statically-compile Python. And on the flip-side of the coin, there are interpreted versions of C++ (AngelScript) and C (CINT).

LT's Python looks like Python and, in some places, behaves like interpreted Python. In other places, it looks like python and behaves like beautifully-crafted-and-optimized statically-compiled C.

Also, four more points:

1. Python's numpy library has been shown to match the performance of native C for large computations. That's because it's calling native C libraries...so essentially there is very little difference.

2. Python's default memory management is refcounting, GC is optional. This is, in my mind, perfect. For those who aren't great with memory management, leave the GC on. For those who know how to use refcounting without ever needing GC (aka know how to never create ref cycles), we can simply turn off the GC (as, of course, will be the case for LT) and have the performance of just refcounting (which, by the way, is what the old LT engine used, just in C++).

3. For those who want to run serious computation in Python, pypy's dynamic analysis and JITing is nothing short of magical. Use it and enjoy the order-of-magnitude performance increase for general computation.

4. Above all else, the ease of manipulating sequences, collections, strings, etc. in Python makes it an incredible choice for just about anything, if not as the language that executes the program, then as the language that generates the C that will execute the program (LT's Python-to-native magic is written in...surprise...Python! At some point, once it is powerful enough, I will be able to use it to compile itself to native code so that Python-to-native can be even faster :geek: )

(Just to balance out all this positive, there are plenty of design decisions that I don't like about Python. But above all it was the ideal choice for LT.)
“Whether you think you can, or you think you can't--you're right.” ~ Henry Ford
User avatar
JoshParnell
Developer
 
Posts: 4255
Joined: Sun Oct 07, 2012 3:06 pm
Location: Baton Rouge, LA

Re: How to program in Python + Paste Code for review/help

Postby Achati » Thu Apr 07, 2016 1:10 pm

by now i really wonder why you don't use something like your own DSL build on top of a language like C, C++ or python maybe
or rather something that is not necessarily bound to text and code like this https://www.jetbrains.com/mps/
IRC "In Josh we trust"
Achati
Ensign
 
Posts: 18
Joined: Fri Jan 24, 2014 3:54 am
Location: Berlin, Germany

Re: How to program in Python + Paste Code for review/help

Postby Jason S » Thu Apr 07, 2016 2:01 pm

I own the website http://www.pythoncoding.com

I should really add more to it, but it does have a neat example of starting a 2d top down game which you can use as a starting point for your creation.

http://www.pythoncoding.com/areas/games/
Jason S
Commander
 
Posts: 208
Joined: Wed Nov 21, 2012 8:43 am

Re: How to program in Python + Paste Code for review/help

Postby ChrisHC » Thu Apr 07, 2016 4:13 pm

I follow Limit Theory since the Kickstarter (and i'm a backer).

But the news that we can write mods/extensions in Python is the single most awesome news since Josh came back.

Great choice, Josh!
ChrisHC
Recruit
 
Posts: 6
Joined: Fri Jan 11, 2013 6:56 pm

Re: If you want to learn how to program in Python...

Postby Grumblesaur » Sat Apr 09, 2016 10:22 pm

Flatfingers wrote:(Beyond the indentation-as-scope-control silliness. :silent: )

Grumble away. :)


You know, if you're going to moan about indentation marking scope, that would lead me to believe that you're not indenting your ifs, fors, and functions in your braced-language code.

Honestly, you're going to be indenting anyway. Forcing people to indent if they mightn't otherwise means readability is forced as well, and Python is all about readability. It's a total non-issue for anyone who indents when they reach a new scope nesting level anyhow.
User avatar
Grumblesaur
Moderator
 
Posts: 1992
Joined: Sun Dec 02, 2012 8:57 pm
Location: Spotsylvania, VA, USA

Re: How to program in Python + Paste Code for review/help

Postby Dinosawer » Sun Apr 10, 2016 3:36 am

While I completely agree with you, we had this conversation very extensively :ghost:
Warning: do not ask about physics unless you really want to know about physics.
The LT IRC / Alternate link || The REKT Wiki || PUDDING
Image
User avatar
Dinosawer
Admiral
 
Posts: 5808
Joined: Fri May 09, 2014 1:08 pm
Location: Belgium

Re: If you want to learn how to program in Python...

Postby KingMoo » Mon Apr 11, 2016 3:02 am

Grumblesaur wrote:
Flatfingers wrote:(Beyond the indentation-as-scope-control silliness. :silent: )

Grumble away. :)


You know, if you're going to moan about indentation marking scope, that would lead me to believe that you're not indenting your ifs, fors, and functions in your braced-language code.

Honestly, you're going to be indenting anyway. Forcing people to indent if they mightn't otherwise means readability is forced as well, and Python is all about readability. It's a total non-issue for anyone who indents when they reach a new scope nesting level anyhow.


I go for the "all code on a single line" approach.
KingMoo
Ensign
 
Posts: 13
Joined: Thu Aug 29, 2013 4:07 am

Re: If you want to learn how to program in Python...

Postby Grumblesaur » Mon Apr 11, 2016 1:40 pm

KingMoo wrote:I go for the "all code on a single line" approach.

Code: Select all
for x in range(100):print('Fizz'*(x%3>1)+'Buzz'*(x%5>3)or str(x+1))+'\n'
User avatar
Grumblesaur
Moderator
 
Posts: 1992
Joined: Sun Dec 02, 2012 8:57 pm
Location: Spotsylvania, VA, USA

Re: If you want to learn how to program in Python...

Postby FormalMoss » Tue Apr 12, 2016 10:48 am

Grumblesaur wrote:
KingMoo wrote:I go for the "all code on a single line" approach.

Code: Select all
for x in range(100):print('Fizz'*(x%3>1)+'Buzz'*(x%5>3)or str(x+1))+'\n'


RESULT: :D
Code: Select all
>>> for x in range(100):print('Fizz'*(x%3>1)+'Buzz'*(x%5>3)or str(x+1))+'\n'
...
1

2

Fizz

4

Buzz

Fizz

7

8

Fizz

Buzz

11

Fizz

13

14

FizzBuzz

16

17

Fizz

19

Buzz

Fizz

22

23

Fizz

Buzz

26

Fizz

28

29

FizzBuzz

31

32

Fizz

34

Buzz

Fizz

37

38

Fizz

Buzz

41

Fizz

43

44

FizzBuzz

46

47

Fizz

49

Buzz

Fizz

52

53

Fizz

Buzz

56

Fizz

58

59

FizzBuzz

61

62

Fizz

64

Buzz

Fizz

67

68

Fizz

Buzz

71

Fizz

73

74

FizzBuzz

76

77

Fizz

79

Buzz

Fizz

82

83

Fizz

Buzz

86

Fizz

88

89

FizzBuzz

91

92

Fizz

94

Buzz

Fizz

97

98

Fizz

Buzz


Grumblesaur: So why, if I try to single line, does this piece of code fail?
while True:for i in ["/","-","|","\\","|"]:print "%s\r" % i,


Code: Select all
>>> while True:for i in ["/","-","|","\\","|"]:print "%s\r" % i,
  File "<stdin>", line 1
    while True:for i in ["/","-","|","\\","|"]:print "%s\r" % i,
                 ^
SyntaxError: invalid syntax
YAY PYTHON \o/

In Josh We Trust
-=326.3827=-


User avatar
FormalMoss
Captain
 
Posts: 978
Joined: Fri Jun 06, 2014 8:06 am

Re: How to program in Python + Paste Code for review/help

Postby Grumblesaur » Tue Apr 12, 2016 11:21 am

You can't do nested flow control inline in Python.

EDIT: At least, not nested loops. You can do an if-statement inside a for- or while-loop in one line, I think.
User avatar
Grumblesaur
Moderator
 
Posts: 1992
Joined: Sun Dec 02, 2012 8:57 pm
Location: Spotsylvania, VA, USA

PreviousNext

Return to Scripting & Modding



Who is online

Users browsing this forum: No registered users and 2 guests