Welcome, Guest
A place to meet other Developers
  • Page:
  • 1
  • 2

TOPIC: Python Newbie

Python Newbie 6 years 6 months ago #14840

  • 600WPMPO
  • 600WPMPO's Avatar
  • Offline
  • Moderator
  • Posts: 3788
  • Thank you received: 557
  • Karma: 233
Talentless, I have decided to learn python by myself.

I am very scared.

The first step is, obviously, downloading python. Which one: The current versions are Python 2.7.1 and Python 3.2. Which one do I download?

Is there any other program I need?

How do you suggest I begin?

I guess I'll be asking for your help in this thread here...
Now Playing: The ComicRack Manual (Online)

See my new comics & gadgets on: Tumblr!
The administrator has disabled public write access.

Re: Python Newbie 6 years 6 months ago #14845

  • Stonepaw
  • Stonepaw's Avatar
  • Offline
  • Moderator
  • Posts: 921
  • Thank you received: 268
  • Karma: 173
Don't worry it's not that scary. :)

ComicRack currently uses IronPython 2.7 which is based off of Python 2.7. So I would get that one.

If you are going to develop scripts I would learn python first and then learn the differences in IronPython once you have a good grasp on python.

The official python tutorial isn't bad and you'll want to bookmark the documentation site for reference.

I've got a book on my computer called Beginning Python. I don't remember if it is any good or not but it's worth a try.

Programs:

Notepad and wordpad are good first tools to write scripts in.

The IDLE that comes with python is something I use pretty often. It is a text editor to write scripts with in addition to a shell you can quickly try things out in.
The administrator has disabled public write access.

Re: Python Newbie 6 years 6 months ago #14846

  • cbanack
  • cbanack's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 1328
  • Thank you received: 508
  • Karma: 182
Also, remember that this is IronPython you'll be working with, not Python. IronPython is special because it lets you program in the Python programming language, but at the same time use Microsoft's .NET libraries for things like graphics, networking, file management, etc.

cYo hasn't included the standard python libraries in ComicRack's IronPython, either, so really you don't have a choice but to use the .NET libraries (the standard python libraries also include lots of stuff for networking, file management, and even some graphics, but they're not available to you in ComicRack.)

Instead of thinking of yourself as learning how to be a Python programmer, it's easier to think of yourself as learning how to use the .NET framework via the Python programming language, since that's what you'll really be doing (especially if you want to do anything involving windows/graphics/etc.)

For what it's worth, I use Eclipse + the PyDev plugin as my development tool for writing CVS. (Eclipse is a pretty steep learning curve for someone who's just starting out as a programmer, though, so you're probably better to start out with a simple text editor like Stonepaw suggests.)

You'll want to find a good .NET tutorial somewhere (maybe search on stack StackOverflow?)

I often refer to this .NET library reference:

msdn.microsoft.com/en-us/library/d11h6832.aspx

I also found this "cookbook" to be incredibly useful when I was first trying to puzzle together how to use .NET libraries from within IronPython:

www.ironpython.info/index.php/Contents



Edit: consider this stuff I just said to be "part 2" of your scriptwriting journey. Stonepaw is right, learn plain old python first.
Last Edit: 6 years 6 months ago by cbanack.
The administrator has disabled public write access.

Re: Python Newbie 6 years 6 months ago #14871

  • 600WPMPO
  • 600WPMPO's Avatar
  • Offline
  • Moderator
  • Posts: 3788
  • Thank you received: 557
  • Karma: 233
Thanks Stoney & cbanack for the encouragement! :)
Stonepaw wrote:
If you are going to develop scripts I would learn python first and then learn the differences in IronPython once you have a good grasp on python.
I have begun with trying to understand the basics of how to handle strings, adding strings and using format specifiers. Most things I am getting, but there are a few basic things I would wish to ask you.

For this example code, what does %s exactly signify?
>>> 'John Q. %s' % ('Public')

This code has the escape backslash:
>>> ‘And he said \’this string has escaped quotes\’’
Here I am having a trouble understanding why after the backslash, the quoted text is not placed like this:
>>> ‘And he said \’this string has escaped quotes'\’

I am sorry for asking noobish question, but the title of the thread says it all :blush:
Now Playing: The ComicRack Manual (Online)

See my new comics & gadgets on: Tumblr!
Last Edit: 6 years 6 months ago by 600WPMPO.
The administrator has disabled public write access.

Re: Python Newbie 6 years 6 months ago #14879

  • cbanack
  • cbanack's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 1328
  • Thank you received: 508
  • Karma: 182
600WPMPO wrote:
For this example code, what does %s exactly signify?
>>> 'John Q. %s' % ('Public')

It's a special python idiom (trick) that allows you to create a new string out of two other strings. More directly, it looks like this:

string1 % ( string2 )

Where string1 contains a "%s". The %s is replaced by string2. The example expression you gave evaluates to 'John Q. Public' when all is said and done. Here's an example that might make more sense:
student = '600WPMPO'
window_title = "%s is learning Python!" % ( student )
After those two lines of code have executed, the window_title variable contains the string "600WPMPO is learning Python!". Notice that I used " and ' interchangeably, because in Python they both do the same thing--create a string.
This code has the escape backslash:
>>> ‘And he said \’this string has escaped quotes\’’
Here I am having a trouble understanding why after the backslash, the quoted text is not placed like this:
>>> ‘And he said \’this string has escaped quotes'\’

I am sorry for asking noobish question, but the title of the thread says it all :blush:
These are good questions! Noticing and wondering about details like that is something that all good programmers must do.

In all programming languages, there are certain characters that you simply cannot put into a string, for various reasons. The example you found is pretty straightforward; you can't use ' inside a string that is also described with ', because that would end the string early. So if I want to add ' to the string 'Cory says Hi 600!' I can't do it, because as you can see, the start and end of the string is already marked with '. In other words, I could do this:
x = 'Cory says "Hi 600!"'
or I could do this:
x = "Cory says 'Hi 600!'"
but not this:
x = 'Cory says 'Hi 600!''
and not this:
x = "Cory says "Hi 600!""

Remember, you can create strings in python using either ' or " characters--the reason Python lets you do both is specifically for situations like this, so you don't have to use the \ character.

However, you asked about the \ character.

The following two characters are called an 'escape sequence': \'

The escape sequence \' is just another way of saying ' in strings when you couldn't otherwise use the ' character (or any other time you want to use it, actually). So imagine that python replaces every \' with a ' when it is reading your code. Even though you can't use this:
x = 'Cory says 'Hi 600!''
you CAN use this:
x = 'Cory says \'Hi 600!\''

There are many other escape sequence. As you might guess, \" is the escape sequence for ". I won't go into the others, they are kind of an advanced trick, but trust me there are lots.
Last Edit: 6 years 6 months ago by cbanack.
The administrator has disabled public write access.
The following user(s) said Thank You: 600WPMPO

Re: Python Newbie 6 years 6 months ago #14884

  • 600WPMPO
  • 600WPMPO's Avatar
  • Offline
  • Moderator
  • Posts: 3788
  • Thank you received: 557
  • Karma: 233
cbanack wrote:
It's a special python idiom (trick) that allows you to create a new string out of two other strings. More directly, it looks like this:
string1 % ( string2 )
Yes.. that is making sense to me. I am gradually understanding it....
>>> '%s plus %s equals %s' % (1,1,2)
'1 plus 1 equals 2'
cbanack wrote:
imagine that python replaces every \' with a ' when it is reading your code.
Now, I understand! :-)

It is feeling very overwhelming to understand and remember so much information at once. So far, I have got a basic knowledge of sequences, functions, strings, lists, tuples, methods.

:laugh: Here is some python fun that places me at the end:
>>> x = ['cYo', 'stonepaw', 'cbanack', 'Oo', '600wpmpo']
>>> x.sort(key=len)
>>> x
['Oo', 'cYo', 'cbanack', 'stonepaw', '600wpmpo']
A few things always confuse me. Like, when do I hit a space, and when do I don't? Like in case of 'x = 123', I hit space between the x & the =. But, I do not need a space here: int(month)

Also, some places have square brackets [], and some have (). Where i which one, i confuse..:unsure:

Atleast "" and '' are the same (with a suble difference)!
Now Playing: The ComicRack Manual (Online)

See my new comics & gadgets on: Tumblr!
Last Edit: 6 years 6 months ago by 600WPMPO.
The administrator has disabled public write access.

Re: Python Newbie 6 years 6 months ago #14885

  • pescuma
  • pescuma's Avatar
  • Offline
  • Expert Boarder
  • Posts: 115
  • Thank you received: 16
  • Karma: 21
600WPMPO wrote:
A few things always confuse me. Like, when do I hit a space, and when do I don't? Like in case of 'x = 123', I hit space between the x & the =. But, I do not need a space here: int(month)

You can put spaces prety much anyway you want (except from the begining of the line). So
x = 123
,
x=123
,
x =                 123
are the same thing.
600WPMPO wrote:
Also, some places have square brackets [], and some have (). Where i which one, i confuse..:unsure:

[] are used to index something. Like if you want the 3 element in the array you use [3].
() are used to send parameters to a function. So you call sum(a,b)

For example, if you see:
x = a[3]
in your code, probably a is a list of something and you are getting the 3rd element, and if you see
x = a(3)
you are calling function 'a' passing 3 as an argument.

Sometimes (for example maps and initialization of arrays) that get a little confusing, I know, but you get used to it with time
The administrator has disabled public write access.
The following user(s) said Thank You: 600WPMPO

Re: Python Newbie 6 years 6 months ago #14891

  • 600WPMPO
  • 600WPMPO's Avatar
  • Offline
  • Moderator
  • Posts: 3788
  • Thank you received: 557
  • Karma: 233
Thanks pescuma for the help!

Well, today i learned a bit about mappings, dictionaries in python, the dict function and few more things.

Tomorrow, I'll be learning about conditionals and loops. God help me.

Guys, this is going nowhere. I am learning new things everyday, but I am not certain that I am remembering what I learned yesterday, or before that. And it seems a long long distance before I would be able to make a script. Don't know if I'll be able to go that far... :unsure:
Now Playing: The ComicRack Manual (Online)

See my new comics & gadgets on: Tumblr!
The administrator has disabled public write access.

Re: Python Newbie 6 years 6 months ago #14892

  • cbanack
  • cbanack's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 1328
  • Thank you received: 508
  • Karma: 182
Don't despair...the best way to learn a programming language is to set yourself a small, reasonable goal and then learn what you need to to accomplish that goal. It's much easier to remember things once you've used them for something...
The administrator has disabled public write access.
The following user(s) said Thank You: 600WPMPO

Re: Python Newbie 6 years 6 months ago #14893

  • Stonepaw
  • Stonepaw's Avatar
  • Offline
  • Moderator
  • Posts: 921
  • Thank you received: 268
  • Karma: 173
cbanack wrote:
Don't despair...the best way to learn a programming language is to set yourself a small, reasonable goal and then learn what you need to to accomplish that goal. It's much easier to remember things once you've used them for something...
Well said!

For example try making a smartlist script that pulls any comics where the title is not empty. That way you can practice loops and conditional statements in a real script situation.

That kind of simple script won't require anything from the IronPython library so you can just use the python skills you know.

Just a thought ;)
The administrator has disabled public write access.
The following user(s) said Thank You: 600WPMPO
  • Page:
  • 1
  • 2
Time to create page: 0.225 seconds

Who's Online

We have 221 guests and 3 members online