HomePortalFAQSearchMemberlistUsergroupsRegisterLog in

Share | 
 

 Basic Python Scripting

Go down 
AuthorMessage
Compu-Teck Inc.



Posts : 80
Join date : 2010-04-29
Age : 25

PostSubject: Basic Python Scripting   Fri Apr 30, 2010 8:51 am

Hello! Many people think programming is difficult, but anyone can do it! For example, in this post is the basic "Hello World!" application for Python, one of the easiest programming languages to use! Mind you, this is just scripting!

Input:
Code:
print 'Hello World!'


Output:
>>>
Hello World!


(Note: If you are using Portable Python [or Python v 3.1 or higher], a version of Python for a flash drive, you will have to input it like this:
print('Hello World!')
Your output will be the same)


Last edited by Compu-Teck Inc. on Thu Aug 26, 2010 8:54 am; edited 1 time in total
Back to top Go down
View user profile
Excimer Sun Software

avatar

Posts : 152
Join date : 2010-05-07
Age : 25
Location : USA

PostSubject: correction   Fri May 07, 2010 9:05 am

Correction:
For all those using Python 3.0 or lower must input either print('Hello world!') or print("Hello world!"), with the parenthesis. But if you happen to be using Python 3.1 or greater you may use the syntax; print 'Hello world!' or print "Hello world!", without the parenthesis.
Back to top Go down
View user profile
Compu-Teck Inc.



Posts : 80
Join date : 2010-04-29
Age : 25

PostSubject: Re: Basic Python Scripting   Fri May 07, 2010 9:06 am

Thanks for the correction, Excimer.
Back to top Go down
View user profile
Excimer Sun Software

avatar

Posts : 152
Join date : 2010-05-07
Age : 25
Location : USA

PostSubject: self correction   Tue Jun 01, 2010 1:44 pm

I am going to have to correct myself Embarassed ! It seems that Python 3.0.x is the only Python version that one must include parenthesis for one's print command with (eg. print("Hello World!")), all other versions of Python appear to allow you to use the print statement without parenthesis (eg. print "Hello World!"). Suspect
Back to top Go down
View user profile
The Fellow
Admin
avatar

Posts : 100
Join date : 2010-04-28
Age : 26
Location : In my head, dreaming up how to shake up the world

PostSubject: Re: Basic Python Scripting   Sun Jun 06, 2010 8:39 am

It allows you to not have to, but alot of the time you can do it if you want.
Back to top Go down
View user profile http://compilecrazy.forumotion.net
Excimer Sun Software

avatar

Posts : 152
Join date : 2010-05-07
Age : 25
Location : USA

PostSubject: re:Basic Python Scripting   Mon Jun 07, 2010 9:01 pm

Well...possibly true, but Pyscripter (one of the more recent IDEs for Python, for those who don't know) returns a syntax error upon byte-compiling (for those new to programming, don't worry about that term I just used...yet) the code whenever I leave out the parenthesis in Python 3.0.x. So I would recommend that everyone out there reading this thread and planning on trying their hand at Python 3.0.x play it on the safe side and put in the parenthesis every time when using this Python version. Otherwise don't worry about it because it seems that none of the other versions of Python seem to have even the faintest objection to the programmer leaving the parenthesis out and just using quotes.
Back to top Go down
View user profile
Compu-Teck Inc.



Posts : 80
Join date : 2010-04-29
Age : 25

PostSubject: Re: Basic Python Scripting   Tue Aug 24, 2010 1:32 pm

Well, as I said in ESS's First C program post, I am going to explain how this program works. Don't worry, it's quite simple! Let's look at the code again:

Input:

Code:
print 'Hello World!'

Output:

>>>
Hello World!


This is one of the simplest codes in Python (and for any other language, but that's beside the point). What happens is by using the "print" command, you are telling Python that what is typed next is to be transferred directly to the output screen. Next, the string (words) "Hello World!" are what you are telling Python to print. NOTE: ANYTHING INSIDE THE QUOTES WILL BE PRINTED!! If you forget the exclamation mark, it will be excluded. Of course, Python will not bother you with grammar, just proper syntax. Well, I hope this makes it easier for anyone who does not quite know how this program works.
Back to top Go down
View user profile
gamerboy

avatar

Posts : 37
Join date : 2010-08-27
Age : 33
Location : Germany

PostSubject: Re: Basic Python Scripting   Fri Aug 27, 2010 5:14 pm

okay, but im assuming (didnt test) that it would show in a console window when opened. what is the command(s) for opening a window? ill guess first, simple guess, but it works on qbasic, so let me try:
Code:
Open Window (x, y)
Back to top Go down
View user profile http://gamerboy8864hacks.freeforums.org
Excimer Sun Software

avatar

Posts : 152
Join date : 2010-05-07
Age : 25
Location : USA

PostSubject: Re: Basic Python Scripting   Sat Aug 28, 2010 9:20 am

All you have to do is have Python installed. Once that's done you go to the command line and type 'python', without the quotes, and press enter. This takes you to an interactive Python interpreter, kinda like a command line where, instead of being bash or cmd, the commands are Python. For this tutorial, you would then type in print("Hello World!") or print "Hello World!", depending on your version of Python, and press enter. It should now print 'Hello World!' to the console screen. You can also type this code into a text file, save it with the '.py' extension, then go to the command line, cd (or chdir) to where you saved the .py file and type 'python yourfilenamehere.py' and press enter and that will give the same output.
Back to top Go down
View user profile
gamerboy

avatar

Posts : 37
Join date : 2010-08-27
Age : 33
Location : Germany

PostSubject: Re: Basic Python Scripting   Sun Aug 29, 2010 4:05 pm

i did not mean that. i meant as in:
open a graphical (internet explorer, etc.) window. Not a console window like command prompt.
Back to top Go down
View user profile http://gamerboy8864hacks.freeforums.org
Excimer Sun Software

avatar

Posts : 152
Join date : 2010-05-07
Age : 25
Location : USA

PostSubject: Re: Basic Python Scripting   Sun Aug 29, 2010 5:35 pm

Oh, I see. GUI (Graphical User Interface) programming is an entirely different topic. Unfortunately, in Python you can't just create a window like in some languages, you have to write specific code to do it, which varies depending on your program. Otherwise, the only way to run your Python programs is as terminal applications. I'll try to post a Python GUI tutorial once I figure it out myself (I can't seem to get it to work right for some reason.).
Back to top Go down
View user profile
Compu-Teck Inc.



Posts : 80
Join date : 2010-04-29
Age : 25

PostSubject: Re: Basic Python Scripting   Mon Aug 30, 2010 8:59 am

Yeah, I have been messing with GUI's for about a month and a half and I can't get to work yet either...
Back to top Go down
View user profile
gamerboy

avatar

Posts : 37
Join date : 2010-08-27
Age : 33
Location : Germany

PostSubject: Re: Basic Python Scripting   Mon Aug 30, 2010 9:57 am

you know why? GUI's in python can be hard. (i know from experience) try writing one in LOLCODE or myasshurts programming languages. harder. then try in C, C#, or C++. hard, but errors are diagnosed!
Back to top Go down
View user profile http://gamerboy8864hacks.freeforums.org
Excimer Sun Software

avatar

Posts : 152
Join date : 2010-05-07
Age : 25
Location : USA

PostSubject: Re: Basic Python Scripting   Sat Sep 25, 2010 5:29 pm

If you are interested in making Python GUIs, take a look at PAGE. It's a WYSIWYG editor for Python GUIs. It's based on visual Tcl and supports all GUI elements and widgets from the Tkinter and Pyttk GUI APIs.
Back to top Go down
View user profile
Compu-Teck Inc.



Posts : 80
Join date : 2010-04-29
Age : 25

PostSubject: Re: Basic Python Scripting   Mon Sep 27, 2010 1:20 pm

Do you know any way I could get this?
Back to top Go down
View user profile
Excimer Sun Software

avatar

Posts : 152
Join date : 2010-05-07
Age : 25
Location : USA

PostSubject: Re: Basic Python Scripting   Tue Oct 05, 2010 8:51 am

Here's its sourceforge page: Linky
Back to top Go down
View user profile
Compu-Teck Inc.



Posts : 80
Join date : 2010-04-29
Age : 25

PostSubject: Re: Basic Python Scripting   Tue Oct 05, 2010 1:22 pm

Thanks!! pirat
Back to top Go down
View user profile
Excimer Sun Software

avatar

Posts : 152
Join date : 2010-05-07
Age : 25
Location : USA

PostSubject: Re: Basic Python Scripting   Wed Oct 27, 2010 12:42 am

No problem! Also, another really good one (better, actually) is Glade, which makes use of PyGTK, a wrapper lib for GTK+, a cross-platform graphics/GUI API. Here's its home page: Click me!
Back to top Go down
View user profile
Compu-Teck Inc.



Posts : 80
Join date : 2010-04-29
Age : 25

PostSubject: Re: Basic Python Scripting   Wed Oct 27, 2010 1:54 pm

I've recently actually started working with a neat little program called Pygame. It basically allows graphics and sounds to be added to games you make in Python. Quite useful, I must say! I will post a link later in the "Tools of the Trade" section...
Back to top Go down
View user profile
Excimer Sun Software

avatar

Posts : 152
Join date : 2010-05-07
Age : 25
Location : USA

PostSubject: Re: Basic Python Scripting   Wed Oct 27, 2010 9:27 pm

Can it do GUIs, too? I know that it can do 2-D graphics and sound but, otherwise...?
Back to top Go down
View user profile
Compu-Teck Inc.



Posts : 80
Join date : 2010-04-29
Age : 25

PostSubject: Re: Basic Python Scripting   Fri Nov 05, 2010 10:02 pm

I'm not sure.. I'd have to do some research... but if it does, that would be sweet!
Back to top Go down
View user profile
The Fellow
Admin
avatar

Posts : 100
Join date : 2010-04-28
Age : 26
Location : In my head, dreaming up how to shake up the world

PostSubject: Re: Basic Python Scripting   Sat Nov 06, 2010 5:37 pm

Well, it has features that could make the GUI better I guess, but its focus is in games, which don't have do much gui's. If you wanted to do a GUI in python, might I suggest looking at this list of libraries and what not: http://wiki.python.org/moin/GuiProgramming

_________________
Back to top Go down
View user profile http://compilecrazy.forumotion.net
Excimer Sun Software

avatar

Posts : 152
Join date : 2010-05-07
Age : 25
Location : USA

PostSubject: Re: Basic Python Scripting   Sun Nov 07, 2010 12:01 am

Soooooo off topic. If we want to discuss GUI stuff (which it seems we do) this content needs to be split off into an appropriate topic under the advanced section for Python.
Back to top Go down
View user profile
Sponsored content




PostSubject: Re: Basic Python Scripting   

Back to top Go down
 
Basic Python Scripting
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
Compile Crazy :: Programming :: Python :: For Beginners-
Jump to: