What happened to OC? - CLOSED Carnage?!
Sign in to follow this  
Followers 0
SnipeYa

In need of Python mentor

So I downloaded python the other day and im struggling a little... I've not really found anywhere with code i can learn from easily and I'm not sure on how extensions and stuff work.

I'm using the default IDE (IDLE)(I've also got the patch for visual studio but haven't tried it) on my windows machine and once I've worked it out a little better I'd like to rewrite some BASH scripts on my centos machine.
I'm really used to .net,php,bash and javascript and for some reason I'm just really struggling with python. I'm really keen to lean a new language that is cross platform (unlike .net) I just can't quite get a hold on it.

If anyone has some helpful material, tips, that sort of thing I'd really appreciate it. 

NeX likes this

PfXuCLa.png

Share this post


Link to post
Share on other sites

Tiddy-bits:

Learn Python the Hard Way!

 

http://learnpythonthehardway.org/book/

 

(because the hard way is actually easier  ;) )

My job is currently as a software engineer focusing on testing a core application by hoooking in Python scripts to simulate user interaction. I asked WaeV for help and he gave me this exact site. I had the benefit of already having a lot of academic programming under my belt and only needed syntax, but this site covers a lot of really key points to get someone from 0 coding experience to proficient very quickly. I had some annoying issues with immutability, but that site is fantastic on the whole. WaeV is a fuckin G, helped me land a job and get a better apartment while in school. Listen to him

WaeV, xvii and SnipeYa like this

KsqHutE.png

Share this post


Link to post
Share on other sites

The book says Python 2, But Python.org says  2 is now legacy and that 3 is the way to go? Thanks to the python site I have 3 installed already, Should I be reverting back to 2, Or if the differences aren't too big do i just wing it and follow the book and if issues arise just figure it out. 


PfXuCLa.png

Share this post


Link to post
Share on other sites

When Zed first wrote LPTHW years ago, Python 3 was pretty new. What he wrote made lots of sense, especially because almost every Python library was still made for version 2. It was very hard to get work done in Python 3 for a long while.

 

These days, the majority of libraries support 3 (and possibly 2 as well) https://python3wos.appspot.com/

 

Django is a popular Python framework that many people use to build webapps. As of right now, two-thirds of the most-downloaded Django apps are built with Python 3. http://djangowos.com/

 

Most new code is written for Python 3. At this point, the only holdouts are legacy code. Things written years ago that are too important or large to change. YouTube runs on Python 2, for instance.

 

Zed's book is on its third edition, and I expect he doesn't want to expend the effort to update his examples. In a sense, his examples are also legacy code. It's potentially important that you can use Python 2 if you have to work on legacy code, but new stuff really should be written for 3.

 

I recommend using Python 2 to follow Zed's tutorial, but be aware that 3 really is superior. https://wiki.python.org/moin/Python2orPython3

 

----

 

It's easy to have Python 2 and 3 installed at the same time. If you want to switch which version is the default, just change their order in your "Path" environment variable.

 

The easiest way to edit environment variables on Windows is with RapidEE, like so. http://www.rapidee.com/en/about

 

rapidee.png

 

If you want Python 2 to be the default, make sure C:\Python27 is earlier in the list.

If you want Python 3 to be the default, make sure C:\Python34 (or whichever version is latest) is earlier in the list.

 

You can change the Path order at any time.

Share this post


Link to post
Share on other sites

I've decided seeing as I will only be writing stuff from scratch, py3 seems to be the way to go for me (rather than use 2 which i may never use again). Its been going well I've been following that book and adapting the examples to py3, all seems to be going nicely so far.

But I'm getting restless, and I wanted to throw myself into the shallows. Get my feet wet. So I went to install a module named "paramiko" so I can try send ssh commands to my linux server. But I've stumbled upon a snag...

 

I keep getting errors like this while trying to use pip

Command "C:\Python34\python.exe -c "import setuptools, tokenize;__file__='C:\\Users\\SnipeYa\\AppData\\Local\\Temp\\pip-build-sic00nz5\\pycrypto\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record C:\Users\SnipeYa\AppData\Local\Temp\pip-jlh2b0w2-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\SnipeYa\AppData\Local\Temp\pip-build-sic00nz5\pycrypto



I'm not sure why its doing stuff in my temp directory, The environment variable is set correctly to my python folder, I'm not sure whats up...  :(


PfXuCLa.png

Share this post


Link to post
Share on other sites

Ach, compiling things already? :P  This is too applicable: http://heeris.id.au/2014/if-programming-languages-were-harry-potter-characters/

Python = Harry Potter

C = Voldemort

But Python harbours a terrible secret. The reason that many of its spells libraries are so powerful is that buried underneath, in its most hidden depths, there lurks a sinister, terrible core of ANSI FLIPPIN’ C!

“Why can’t I install this package on Windows,” you innocently wonder. “What’s this about MSVC and assignment from incompatible pointer types hey wait a second BY MERLIN’S BEARD NOOOOO” and then all you can see are visions of being a snake killing the people you love while you hear corrupting whispers in a language you wished you didn’t understand.

 

Pip can download+install pure python packages with no problems. But when C gets involved, it's harder to be cross platform.

 

I don't have a lot of time to help just this instant, but it comes down to:

  • Linux traditionally uses the GCC compiler.
  • Windows traditionally uses the MSVC compiler. (Visual Studio)
  • Libraries compiled by one compiler cannot be used by the other compiler.
  • GCC does actually run on Windows. It was ported under the name "MinGW" (sidenote: there is also a separate project "MinGW-w64", it's confusing)
  • Python for Windows can be compiled by MinGW or MSVC
  • ergo pip needs you to set up the correct compiler in order to install packages with C components.
An easy way out of this mess is for Christoph Gohlke to have pre-compiled a package for you: http://www.lfd.uci.edu/~gohlke/pythonlibs/

Unfortunately he doesn't have pycrypto.

 

Second-easiest would be to find a Python distribution that includes a C compiler, such as WinPython: http://winpython.github.io/

It comes all together, so Python and the C compiler are hooked up from the start.

 

Anaconda is another distribution which seems to use its own non-pip package manager, and it has pycrypto: http://docs.continuum.io/anaconda/index

 

Hardest would be to get MSVC or MinGW set up correctly.

Share this post


Link to post
Share on other sites

Haha, what makes you think so?

I expect you're talking about Python's dynamic scoping, and I agree it's not the greatest idea. I prefer lexical scoping.

 

This snippet works with both dynamic and lexical scoping. Variable `a` is defined by the time you use it.

a = 1
def foo():
    print(a)
foo()
This snippet breaks in both dynamic and lexical scoping. Variable `a` is NOT defined by the time you use it.

def foo():
    print(a)
foo()
a = 1
This snippet DOES work in dynamic scoping, but does NOT in lexical scoping.

def foo():
    print(a)
a = 1
foo()
 

Lexical scoping is basically "you can only see variables defined on earlier lines", whereas dynamic scoping is "you can see variables in outer levels, as long as they exist by the time your code is executed".

I think lexical scoping is far easier to think about. But Python is generally good in most other ways, so I tolerate it.

Zukyak likes this

Share this post


Link to post
Share on other sites
Sign in to follow this  
Followers 0
  • Recently Browsing   0 members

    No registered users viewing this page.