[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Recently started relearning Python for uni and was wondering

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 56
Thread images: 7

File: python.png (80KB, 1000x1000px) Image search: [Google]
python.png
80KB, 1000x1000px
Recently started relearning Python for uni and was wondering what the main advantages of the language are? Is it just the sheer amount of libraries and modules available? I've come from using C,Java,Haskell and a little bit of MATLAB.
>>
>>58444895
The main advantages of the language are simplicity and readability. Anyone can learn to use Python, from a child to a grandmother.

Python code is easy to read by humans so it's great for collaboration, and the simplified syntax allows to you do more with less code.

The sacrifice it makes is performance. It's a very high level language (it's interpreted) and compared to something like C it's blown of the water.
>>
>>58444895
>>58444930

Also yeah, there's a shit load of modules available. The python community is *very* active worldwide and there's a module/bindings/API wrapper/whatever for just about anything you could want to do.
>>
>>58444930
>>58444970
Yeah looking at the code now I can see why it's so widely used; it barely even feels like syntax.

Any idea why it's used so much for mathematical/scientific computing if it sacrifices performance? Or is it just to spare everyone having to learn pointers
>>
>>58445028
>scientific computing
The performance-critical bits are were all written in C and Fortran many years ago. Python is used as a "glue" language to quickly and easily combine these C/Fortran libraries without having to worry about memory management, the compile-run-debug cycle, etc. Also, its dynamic nature makes possible really useful things like Jupyter notebooks and quick prototyping for scientific models.
>>
>>58445157
Good answers thanks. Jupyter Notebooks look cool
>>
>>58444970
Too bad ALL python libraries are shit.
>>
>>58444895
Really fast development + libraries for everything + cross platform.
>>
>>58445264
The requests library is pretty much the crème de la crème
https://github.com/kennethreitz/requests
It's really, really clean and well done
>>
>>58445291
I don't know what that is, I am a gaybe dbelover and last time I tried python, all the graphics libraries were horribly broken B-)
>>
>>58444895

If you're used to those other languages, you'll be surprised by how terse and relatively straightforwards Python is. Coming from C, Java and Haskell, you'd be surprised at how quickly you can "get shit done" with Python.
>>
Question here, whats the pros and cons when it comes to interpreted and compiled languages? Are we just getting the benefit of the compiler optimizing code when we compile code? Is there anything more than that?

Also I heard that python being interpreted is a half lie, it actually semi compiles part of the code whatever that means
>>
>>58445386
Compilers can tell you that your code is shit before you make the mistake of running it
>>
>>58445366
Yeah I've been practicing for the last half hour or so and after not using Python for the last few years I'm suprised at how easy I can manipulate arrays and types.

>>58445386
I'm also interested in this if anyone could answer
>>
>>58445342
>I am a gaybe dbelover
what did he mean by this?
>>
File: buffer overflow exploit.png (39KB, 571x816px) Image search: [Google]
buffer overflow exploit.png
39KB, 571x816px
>>58445442
>imblyign imbligations
>>
>>58445366
>you'd be surprised at how quickly you can "get shit done" with Python.

For sure. If you're building something where speed is absolutely critical, like a game engine, do not use Python.
If you need to get something done quickly and efficiently, use Python.

I just wrote this in response to your post - it reads in links from a text file and sees if they're working. aka a link checker

import requests

with open('links.txt', 'r') as file:
links = file.readlines()

for link in links:
http = requests.get(link)
if http.status_code == 200:
print(f'{link} works')
else:
print(f'{link} failed')


I'm no expert but it's pretty cool to write something useful with so little code.
>>
>>58445473
He means shit like trying to multiply a number by an array, or trying to access an object property that doesn't exist.

No one is going to claim that typed languages preclude errors.
>>
>>58445442
Thats pretty obvious, but is that it? How is that even a benefit towards compilation to be honest? Its a lot faster to interpret code run line by line as it is to compile the actual program

Python you can spam ctrl+1 with a keybind till something works where as in C you'd have to spam gcc helloworld.c helloworld -o followed by ./helloworld or something
>>
>>58445386
>>58445457

Compiled:
when the code is compiled it is output as object code. These are instructions that your CPU processess without any interpretation needed.

Interpreted:
Instructions are compiled into object code on-the-fly by an interpretor. This means that every time a command is executed, there are additional commands which must be executed which output machine language

Look at it this way:
High level languages at some point must be turned into processor-executable object code like what I have pictured... this can either all be taken care of before hand (compiled) or taken care of as each instruction is read (interpreter)


>I heard that python being interpreted is a half lie
It tries to compile what it can ahead of time. but it is still an interpreted language. Also, some of python libraries are actually C libraries wrapped with python (such as socket)
>>
File: objdump.png (90KB, 635x756px) Image search: [Google]
objdump.png
90KB, 635x756px
>>58445549
>>58445533
>>58445386
>>58445457
forget pic.

anyways, this conversion from high level to object code needs to happen at some point. compilers do it before hand, thus leaving a faster program, wheras interpretative languages work it in while executing, leading to slower programs
>>
>>58445028
Most of the math done with it doesn't need that the performance of a low-level language. Most scientists don't want to waste time learning C, yeah.

The stuff that gets processed into supercomputers and such are normally written in Fortran though. (old as fuck, but very easy to learn and lends itself nicely to mathematical applications)
>>
>>58445549
>>58445564
I see, so what about python files converted into a runnable .exe? I assume just because of the nature of the language difference between C and Python, that the python.exe will still be slower because of the way its compiled?
>>
>>58445640
Distribution is one of the huge flaws in Python. You will not have a good time if you're trying to make exes lol.

Hopefully in the future it will become more a priority for developers.
>>
>>58445640
> I assume just because of the nature of the language difference between C and Python, that the python.exe will still be slower because of the way its compiled?

Maybe, maybe not.

Because the python is converted into object code, that object code will execute just as fast as object code generated in any other language... once the object code is made it doesnt matter what higher level language it came from, its the same object code.

--but--

You are using somebodies third party program to compile this object code from python source... how optimized is this object code?

a gcc compiler will give you very efficient object code from a given C source file. But will your 3rd party open source 'python to exe' program make efficient object code out of python source? I cant answer that.
>>
>>58445640
There's no way to compile an entire Python program to machine code ahead of time. PyPy is an interpreter that compiles only certain sections it determines are CPU-bound, but you'd still need to bundle the entire PyPy interpreter with your program into that .exe. And yeah, it would be slower but in the overwhelming majority of cases the difference is literally unnoticeable.
>>
>>58445660
Hmm sorry I dont really understand that sentence, what do you mean distribution is a flaw in python, as in no one has it installed and no one cares about it? Bretty confused
>>
>>58445660
>>58445680

>Distribution is one of the huge flaws in Python
Yes. you can only efficiently distribute python source code for use with python interpreters. If you really want compiled object code that badly, then just write your program in a language that is meant to be compiled.
>>
>>58445677
This was the answer I was looking for, thanks
>>
>>58445679
>There's no way to compile an entire Python program to machine code ahead of time
There --are-- ways. py2exe is one, it will take a python source and output an executable binary...
>>
>>58445680
By distribution I mean "turning your file into a windows executable (exe) and distributing it to people"

Most people run python from a terminal, and that's pretty much what it was intended for.

python mycode.py


Like this guy said >>58445688 - if your end goal is to make an .exe then Python isn't a good choice.
>>
File: madass.gif (2MB, 320x240px) Image search: [Google]
madass.gif
2MB, 320x240px
>>58445497
>mfw Python is clean
>mfw Python is easy to read
>mfw a 5 year old could understand this
>>
is common lisp slower than python?
>>
>>58445501
You can do type checking in a dynamic language.
>>
>>58445497
>speed is absolutely critical,
>like a game engine
The last AAA game that was properly optimized was never. Doom, maybe.

Games need compiled languages because
their code is so shitty they wouldn't even run if they didn't have the "free" performance boost from a compiled language.
>>
>>58446474

This nigga retarded.
>>
It's a synchronous scripting language with artificial threading (because of the GIL) and will crash easy like all scripting languages. Can't properly be compiled.

Like all scripting languages, it does benefit a lot from doing complex tasks in many utility functions however it's only real benefit is a huge fuck ton of libraries and community support.

Syntax wise it's an abomination in my opinion
>>
After python 3 was released, python became irrelevant outside of academia.

It is now the new scheme
>>
>>58444930
I hate this kind of PR shit.

* Not everyone from a child to a grandmother can CODE period. I don't care what the language is. FizzBuzz is a meme because of all the people who read some tutorial or take some class and proclaim "I can code!" when they really cannot.

* Python is no easier to read than other high level languages: VB.NET, C#, JavaScript, Xojo, Swift, etc.

It's easier to rapidly prototype, and in some cases read, than C++ or obj. C. But if you're using either of those, you're using them for something Python can't touch. I would not place it above the .NET languages, Xojo, or Swift for RAD or readability though it can be more concise in some cases.

* Performance wise it sucks even for an interpreted language. And being interpreted is not the reason why it has some readability or RAD advantages over some other languages.
>>
File: Screenshot_2017-01-12-19-08-11.jpg (165KB, 755x435px) Image search: [Google]
Screenshot_2017-01-12-19-08-11.jpg
165KB, 755x435px
So I got this book today, and chapter 2 is just confusing me. So it says do
if name == 'Alice':
print ('Hello, Alice')
But it dosent ever tell me to define Alice.
>>
>>58448808
'Alice' is not a variable like age, it's just a string.
>>
File: ew.gif (2MB, 380x285px) Image search: [Google]
ew.gif
2MB, 380x285px
>>58448789
Almost everything you said is wrong.
>>
>>58448925
But it tells me to do that in the book (pic related)
>>
>>58448972
imagine you would do something like
> if number == 5
you don't need to define 5, computer already knows what it is. In your example 5 is 'Alice', python checks if whatever is in name equals to this 'Alice' string, which it already recognizes.

If it still doesn't make sense you should probably track back and reread the chapter on variables.
>>
>>58449042
Yeah I understand what you are saying.
But why does it give me an error. Shouldn't it just werk. The book tells me it should work
>>
>>58449113
if you only pasted in what is in that picture program will not work because name and age have not been defined

before doing any operations (like comparisons) on variables you need to define them, for example
>name = 'Anon'
>age = 20
>>
>>58449169
Right. I forgot the quotes to make it a string or whatever its called.
>>
>>58444930
Easy to read? Nigga

https://docs.python.org/3/reference/grammar.html

They even have shit like annotations in the fucking language. Easy to read maybe for people who know language design I guess.
>>
File: the_dude.jpg (50KB, 600x426px) Image search: [Google]
the_dude.jpg
50KB, 600x426px
>>58449212
Easy with the racial epithets, this isn't /b/.

You have been warned.
>>
>>58448930


Try encrypting something with AES or making an SFTP connection with pure python code and then say that. Python is as slow as you are.
>>
>>58449285

le reddit --->
>>
>>58445471
gay bed lover
obviously
>>
>>58448930
Well shit with a detailed retort like that....
>>
>>58444895
v e r y e l i t e h a c k e r
e
r
y

e
l
i
t
e

h
a
c
k
e
r


words = str(input('enter first: '))
word2 = str(input('enter second: '))
l = []
l.append(words)
l.append(word2)

x = len(l[0])
y = len(l[1])

grid = []
for i in range(y + 1):
grid.append([])

for i in l[0]:
grid[0].append(i)

count = 1
for i in l[1]:
grid[count].append(i)
count += 1
x = str()
count = 0
for i in grid[0]:
if count == 0:
x += i
else:
x += ' ' + i
count += 1

print(x)
for i in range(1, y + 1):
for x in grid[i]:
print(x)


you can be a leet hacker.
>>
>>58445933
It's about 20-40% slower than C most of the time. Sometimes faster.
>>
>>58445701
>>58445701
>There --are-- ways. py2exe is one, it will take a python source and output an executable binary...

write a hello world. and compile it to binary with that.
then tell me how is it acceptable for a hello world to be 4 mb :^).

pro tip : it literally insert whole python interpreter with your binary each time you compile something.

FUUUCK THAAAAT
Thread posts: 56
Thread images: 7


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.