Some beginner's questions about python

nbaztec

Master KOD3R
Hey guys - I also have a noob query..

I'm thinking of learning a scripting language good enuf to put it up on my resume... and I was hoping to learn python..

But I already have some experience with haskell so what shud I do??! Haskell Or python??
I'd say you can learn both. That's the beauty of Python.
Also why is that every developer/programmer who is using Linux knows python?! :O I just don't get it!!!
Python(or any scripting language for that matter) synergizes well with Linux and it's powerful command line shell. Plus you can use Django on Linux easily. Same can't be said for Windoze users who have been accustomed to mouse clicks and fancy buttons.
 

$$Lionking$$

In the zone
@krishnandu - Ok, that makes sense... thanks! :)

nbaztec - Mayne, I dont want to do both!! :(

I think Ill delay learning both.. :p
 

abhijangda

Padawan
Go for Python. It is Object Oriented, has a very large library, many bindings of Widget Toolkits are available like PyQt, wxPython, PyGTK, can be used to develop a GUI application or a Web Application. Python is one of the most widely used scripting language. Many softwares and web applications/sites are created in Python. Moreover, it has a clean syntax and increases programmers productivity exponentially. Just go for Python, these are just a small number of plus points of Python.
 

nbaztec

Master KOD3R
^Depends. I use single quotes whenever my string has double quotes and vice versa. Triple double quotes for documentation. Triple single for raw text. Rest of the time it's double quotes for me. It all boils down to personal taste IMO.
 
OP
Niilesh

Niilesh

Padawan
Hey guys when I type ./file_name.py in the terminal it says '.' is not recognized.
Does it only run in linux?
^Depends. I use single quotes whenever my string has double quotes and vice versa. Triple double quotes for documentation. Triple single for raw text. Rest of the time it's double quotes for me. It all boils down to personal taste IMO.
Hmm..
So I would have to chose myself?
 

krishnandu.sarkar

Simply a DIGITian
Staff member
Yes that thing is only for linux. (Its already written in the book you are following)

Sent from my LG-P500 using Tapatalk 2 Beta-5
 

gopi_vbboy

Cyborg Agent
python is good for linux...you see so many google services using python on custom linux distro...but it sucks in.windows due to so many abstractions to execute..not so power ful on windows
 

nbaztec

Master KOD3R
Hey guys when I type ./file_name.py in the terminal it says '.' is not recognized.
Does it only run in linux?

Hmm..
So I would have to chose myself?
On Linux:
./ : Current Directory
../ : Parent Directory
~/ : Home Directory

Of these windows supports only ../ for parent directory.
./foo.txt on windows directly corresponds to foo.txt (enter $HOME environment variable)
 
OP
Niilesh

Niilesh

Padawan
Yes that thing is only for linux. (Its already written in the book you are following)

Sent from my LG-P500 using Tapatalk 2 Beta-5
Ok that means She-bang has no use in windows?(in python)
BTW i left that book, I am now following "lean python the hard way" as suggested by coolpcguy.

One more thing - I wanted to know if by default when *.py files are opened it will be executed by python 2.x
If in the she-bang i will refer to the path of python 3.x. then run ./file_name.py then what will happen.
Also how do you specify path in the shebang?(I mean do one has to mention the drive letter?)
Is this right? -
Code:
#!C:\python32 python
 

krishnandu.sarkar

Simply a DIGITian
Staff member
Well she-bang is not the feature of python. Its a feature of unix.

If you provide path of python3 in she-bang it'll execute with python3.

Sent from my LG-P500 using Tapatalk 2 Beta-5
 
OP
Niilesh

Niilesh

Padawan
On Linux:
./ : Current Directory
../ : Parent Directory
~/ : Home Directory

Of these windows supports only ../ for parent directory.
./foo.txt on windows directly corresponds to foo.txt (enter $HOME environment variable)

$HOME environment variable = "~/" or its "$HOME" only?
Can you give an example (for windows)?

Also What's Home Directory?
If a folder has path like this - C:\a\b\c\d\e\f
Then the home directory will be C:\ or C:\a ?
 

krishnandu.sarkar

Simply a DIGITian
Staff member
None. Home in linux is somewhat similar to my documents in windows.

In windows every user has their own my documents, on the other side every linux has their own home directory.

Sent from my LG-P500 using Tapatalk 2 Beta-5
 
OP
Niilesh

Niilesh

Padawan
Well she-bang is not the feature of python. Its a feature of unix.

If you provide path of python3 in she-bang it'll execute with python3.

Sent from my LG-P500 using Tapatalk 2 Beta-5
OK...

None. Home in linux is somewhat similar to my documents in windows.

In windows every user has their own my documents, on the other side every linux has their own home directory.

Sent from my LG-P500 using Tapatalk 2 Beta-5

OK.(again)
 

$$Lionking$$

In the zone
Go for Python. It is Object Oriented, has a very large library, many bindings of Widget Toolkits are available like PyQt, wxPython, PyGTK, can be used to develop a GUI application or a Web Application. Python is one of the most widely used scripting language. Many softwares and web applications/sites are created in Python. Moreover, it has a clean syntax and increases programmers productivity exponentially. Just go for Python, these are just a small number of plus points of Python.

That makes sense....... so python is easy or what??
coz if i go for it this will be my first object oriented language.... :(
 
OP
Niilesh

Niilesh

Padawan
Hey Guys strip this code as small as you can
Code:
from sys import argv
from os.path import exists
script, from_file, to_file = argv
print "Copying from %s to %s" % (from_file, to_file)
# we could do these two on one line too, how?
input = open(from_file)
indata = input.read()
print "The input file is %d bytes long" % len(indata)
print "Does the output file exist? %r" % exists(to_file)
print "Ready, hit RETURN to continue, CTRL-C to abort."
raw_input()
output = open(to_file, 'w')
output.write(indata)
print "Alright, all done."
output.close()
input.close()

I could only think of this -
Code:
from_file = raw_input('input? ')
to_file = raw_input('output? ' )
indata = open(from_file).read()
open(to_file, 'w').write(indata)

The writer says it can be done in one line

Hey did i combine these the two lines like the writer wanted?
Code:
input = open(from_file)
indata = input.read()

to
indata = open(from_file).read()
also it gave an error while closing the file, saying something like that nothing is opened. Can someone explain what the line does?

Also what's the need to close the files? To free up RAM? don't the files get closed when the script ends? So, it's only useful when opening big or many files?

thats why its called python.
once you catch its tail, it'll wrap around you and not let go.
:-o :)
 
Top Bottom