Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4
What're my best options for platform-independent MP3 and FLAC playback in Python? I'm writing a media player to serve as a reference implementation for a new metadata format I'm writing, and most of the stuff that handles MP3 or FLAC either a. only works on Windows or b. is bundled in with a bunch of poo poo focused around game development that I'd rather not distribute with my program (like pygame). Right now I'm settled on pyglet (smaller and simpler than pygame at least) but it would be really keen if I just had a teeny-tiny package (or two, for each format) that did nothing but play back media, modulate the volume, etc.

Adbot
ADBOT LOVES YOU

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4
All you need is a text editor at this point. Don't worry about getting fancy too quick. (I followed the same book and I and several pros I know recommend it to a lot of people, it's a very good intro) Shaw suggesting Atom is a new one, but I just checked and I guess he's updated it since I last looked at the starting chapters.

When you say "framework" I assume you mean an IDE - definitely overkill for you right now (unless you're used to using IDEs with other programming languages - but if you've been programming before, you probably already have a preferred text editor installed)

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4

funny Star Wars parody posted:

Jetbrains makes a lot of really nice stuff and I really like IntelliJ for Java and JavaScript. I found Pycharm to be frustrating to use because most small Python apps aren't organized the way Pycharm seems to try to organize them

Personally, I write all my Java in IntelliJ but only larger Python projects in PyCharm - if it's something small I'm A-OK with not having all the fancy features.

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4

shrike82 posted:

There's nothing odd about talking about dependency injection, outside of DI/IoC being slightly less 'popular' in Python-land due to dynamic typing making it trivial to handle.

As a relative newbie, if dependency injection is less popular in Python than it is in other languages, how do you handle cases in Python that you'd typically use dependency injection for in, say, Java?

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4

Thermopyle posted:

DI isn't exactly uncommon in Python. It's just that because of Python's dynamic nature you don't really need a lot of scaffolding that you need in other languages so it often doesn't go by the Official Pattern Name Dependency Injection. You just write stuff in Python in a pythonic way and then later someone is talking about Python and DI and you go "you know I guess I just did use DI!"

edit: Forgot to add that super() is an effective and easy way of doing DI in python.

I've tried to figure out super() in Python a few times and everything I look at makes no goddamn sense; do you ? have any good resources covering it? I don't mind doing regular old DI for the project I'm doing in Python it would be nice to properly understand how super() works.

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4
Trying to install python-tcod on a Linux Mint 18 machine and run into this error when I run "pip3 install tcod":

code:
Command "/usr/local/bin/python3 -u -c "import setuptools, tokenize;
__file__='/tmp/pip-install-5h2mafwy/tcod/setup.py';f=getattr(tokenize, 'open', open)
(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))"
 install --record /tmp/pip-record-n9d0gjib/install-record.txt --single-version-externally-managed
 --compile --user --prefix=" failed with error code 1 in /tmp/pip-install-5h2mafwy/tcod/
Pretty much everything I google up says "oh you need the python devtools installed" or "you need to update gcc", both of which I've done to no avail. I know that the error code it's giving is linked to GCC but the only things I'm finding relating to this are... again, insuring I have gcc/g++ updated. I do have python3-dev installed but it's saying it's version 3.5 - I've tried installing tcod with both python3 (3.7) and python3.5 (... 3.5). Am I missing something horribly simple? I can't get it installed in a virtual environment, either.

death cob for cutie fucked around with this message at 20:28 on Apr 9, 2019

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4
I can't learn via video about programming; really, I can't learn from video on any topic at all. I have pretty bad ADHD, so I'll have to rewatch a video 4-6 times to catch it all - more if there's lovely editing, weird jumps, etc. On the other side, I have a ridiculously fast reading speed and I don't have to pause/scrub through a video to get back to what I last understood if I missed something - I just flick my eyes back or go back a page. Video tutorials have gotten better than they used to be, but they're still awful IMO.

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4
Please help me understand a Django issue:

Python 3.6, Django 1.10*

code:
request.session['tasks'].append(request.POST['title'])
This does not properly append to the list stored in request.session['tasks']. This appears to be a known issue - except this page is thirteen years old. I've found a few blog posts on the issue suggesting to do something like "request.session.modified = True" or pulling the list out of session, modifying it, and reinserting it into the proper key in session - these are, again, very old pages. I can't seem to find anything modern on the topic, and unfortunately "list" is a common enough word that Google results get clogged with garbage. Normally I'd accept this, except I have a project where this works as expected:

code:
request.session['activity'].append([activity_result, result])
works just fine, repeatedly. I have a few other projects where this is the case as well. I assumed it was some weirdness with shoving something straight into the list right out of request.POST, so I tried this instead:

code:
new_task = request.POST['title']
request.session['tasks'].append(new_task)
with no luck. It appears the only option is to have "request.session.modified = True" somewhere else in the function, but I absolutely have projects where that doesn't occur. I also have projects from other students/staff that manipulate request.session in this way where nothing unexpected happens. I have multiple other projects where I'm shoving lists into session and appending them, and everything works as normal.

What am I missing? Other uses of session work just fine, nothing seems amiss in my settings or in other places in my project. I thought maybe 'tasks' was somehow reserved and tried different key names; I've tried storing strings, ints, tuples, lists, etc. inside the list in session. I've tried multiple iterations of code and can't seem to pin down anything other than "works in other projects, doesn't work here". I'm wondering if I made some small mistake upfront and I'm just continually missing it?

* I teach** intro web development with a company that insists we use Django 1.10 instead of 1.11 for some reason; I appear to have the same problem in 1.11 as well, although I haven't tested as extensively.
** this post may not inspire much faith in my ability to teach - trust me, I'm not having much faith in this today, either

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4

Thermopyle posted:

Keep us updated!

Figured it out: the situations in which I was able to mainpulate a list in session no problem, I was also modifying such as an int or string stored in session, adding/removing a key, etc.

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4
at work we pronounce it "goo-nicorn", no Y sound in there

we're also kind of dinguses, tho

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4
Wait, DataGrip is part of PyCharm? I've been paying for JetBrains Fuckin' Everything for like 20 bucks a month to get both PyCharm and DataGrip

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4

CarForumPoster posted:

The venv folder that pycharm creates is 75MB with only pip20 and setuptools...is that normal?

I can't speak for anything else but I just looked at the folder sizes for two virtual environments I have - one has pretty much nothing and is 9.4MB, and one is an environment I use to teach Django and that's 48MB (Django is about 33MB of that). To test something out, I started a new PyCharm project and had it make a venv, and it's 14.9MB. It looks like PyCharm's process for creating a venv in shoving some extra stuff in there. pip list shows not much installed, but some of the folders inside the venv have some extra stuff. I'm not familiar enough with how venvs are made to explain why PyCharm's venv creation inflates the size of the environment, but there's a difference for sure. It shouldn't be 75MB, though. Unless it's a difference of OS?

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4
Couldn't you just use the functions themselves as dictionary keys? I'm laying in bed and way too lazy to open repl.it on my phone, but I'm pretty sure Python dictionary keys can be any kind of object, including a function - you just wouldn't call it in the dictionary.

e: since you're returning the dictionary that sounds non-ideal - you could create a list of function/string tuples and iterate over that; call the first part of the tuple and update the dictionary using the key of the second part

death cob for cutie fucked around with this message at 10:07 on Aug 28, 2020

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4
To be more specific I was thinking something like this:

code:
calc = {"mean": 0, "variance": 0, ...}

ops = [(np.mean, "mean"), (np.var, "variance") ...]
since if you're going to passing that dictionary anywhere else, having the functions themselves as dictionary keys or having them involved in any way is just going to be kinda confusing for whoever/whatever else is going to be handling them (IMO, at least)

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4
I think something like re.sub() handles this, but I haven't used it before so I can't provide an offhand example for you

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4
I assume the cells are merged like that to permit other parts of the document to have cells be merged in other, more horrifying amalgations? gently caress people who don't use spreadsheets for their intended purpose, IMO

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4
I have what's more or less an academic question: when doing unit testing (via unittest, pytest, nose2, w/e) you're primarily testing based on the output of the function. There's no simple way to test what a function prints to the console rather than what it returns, right? Simple in this case as "able to be explained to a novice programmer, in a way they could grasp without significant difficulty".

(This question is pretty dumb, here's the background: I teach at a code bootcamp and want to introduce unit testing to students sooner so they're not making GBS threads themselves when asked about it during a job interview, and most of our early sample functions we have them write are still occasionally printing stuff. I need like, one more reason to cut as many print statements from the curriculum as soon as possible and this could be the tipping point - if a function relies on a print statement to work properly, and we can't test if it works properly, then it's dumb to be using print() while teaching unit tests.)

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4

Bundy posted:

Just to note dicts are ordered as of 3.6.

hot drat, they are https://docs.python.org/3.6/whatsnew/3.6.html#new-dict-implementation

I was wondering why the last few times I was trying to show that dictionaries aren't ordered to students that it wasn't behaving

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4
I have the following code I whipped up just out of curiosity:

code:
import time

x = 2

while True:
    a = time.perf_counter_ns()
    x = x ** 2
    b = time.perf_counter_ns()
    y = (b - a)
    print(f'Digit size: {len(str(x))} - NS to calc: {y}')
I get output like this:

code:
Digit size: 1 - NS to calc: 1369
Digit size: 2 - NS to calc: 730
Digit size: 3 - NS to calc: 530
Digit size: 5 - NS to calc: 610
Digit size: 10 - NS to calc: 740
Digit size: 20 - NS to calc: 920
Digit size: 39 - NS to calc: 920
Digit size: 78 - NS to calc: 810
Digit size: 155 - NS to calc: 940
Digit size: 309 - NS to calc: 1360
Digit size: 617 - NS to calc: 2140
Digit size: 1234 - NS to calc: 4709
Digit size: 2467 - NS to calc: 13960
Digit size: 4933 - NS to calc: 30299
Digit size: 9865 - NS to calc: 57508
Digit size: 19729 - NS to calc: 57599
Digit size: 39457 - NS to calc: 122307
Digit size: 78914 - NS to calc: 258633
Digit size: 157827 - NS to calc: 541475
Digit size: 315653 - NS to calc: 1131908
Digit size: 631306 - NS to calc: 2390754
...
2390754 nanoseconds is like 0.002 seconds and it's definitely taking my computer more like 2-3 seconds to bash together two 310,000 digit numbers. Is having to do this big calculation loving with Python's timekeeping? Or am I not understanding how to use some of the tools in time correctly?

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4
ooooh, I didn't even think that would be a serious issue

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4
I just had a student a while back ask me about the maximum integer size in Python, I told her "there's not really one" and she was interested in the implications of that - I literally whipped it together in like ten seconds and threw in len(str(x)) just to indicate how big the numbers would get. Using math.log10 is way better, I'm just a math idiot and didn't realize that was a possibility.

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4
yeah now that I realize the nature of the issue I'm sure that taking a very, very, very large number and converting it into its string representation is going to be at least a little time-consuming

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4
I need a confirmation that my hunch is right here, as it's Python-related but involves some stuff I don't normally have to think about :

I teach a Python web development course that uses bcrypt - CFFI is a dependency of bcrypt. I have a student on the new M1 Mac who, when running a Django project where bcrypt gets imported in views, gets a nice long exception that terminates with this:

code:
ImportError: dlopen(/Users/username/Python_stack/django/my_environments/django2/lib/python3.9/site-packages/_cffi_backend.cpython-39-darwin.so, 2): no suitable image found.  Did find:
    /Users/username/Python_stack/django/my_environments/django2/lib/python3.9/site-packages/_cffi_backend.cpython-39-darwin.so: mach-o, but wrong architecture
    /Users/username/Python_stack/django/my_environments/django2/lib/python3.9/site-packages/_cffi_backend.cpython-39-darwin.so: mach-o, but wrong architecture
CFFI appears to not have an ARM64 release, unless I'm misreading it - so short of compiling it herself for her architecture, she doesn't really have any workaround for this, right?

(it feels like the obvious answer is "yes, she's boned" but I also feel like I'm missing something here)

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4
I guess there's also having her run it under Rosetta but that's kind of tedious

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4
Python GUIs: tkinter is still not great to work with, right? What's the good poo poo for making a semi-decent cross-platform GUI without giving yourself hives, PyQt? guizero?

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4

CarForumPoster posted:

What's the use case?

Personally, I 100% won't do anything in tkinter or pyqt and instead make my GUIs in the web browser using Dash. https://dash-gallery.plotly.host/Portal/

I find Dash ridiculously productive and bonus that I can deploy it to free tier heroku in about 5 minutes.

Good question: there's someone who wants a desktop version of VARIA, the Super Metroid randomizer. You can run it from the command line but not everyone is like, comfortable with that, so I figured I'd take the time to learn how to make a decent Python GUI and package the whole thing as an .exe for ease of use. I could probably cram it all into an Electron app but I'm more interested in using this as an excuse to learn a GUI toolkit than I am in learning how to get Electron going.

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4
Agreed, more or less, but there's a few people who seem to want it for one reason or another (unstable/metered internet connection or frequent travel) and it's giving me a good excuse to poke at some stuff relating to the project I'm interested in.

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4

skull mask mcgee posted:

musicbrainz picard is built using Python and PyQt and it’s no more difficult to install and use than any other software I’ve used

Oh hey I use Picard for FLAC file management, neat!

anyways I'm sorry to have summoned this tedious conversation into existance

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4
So I was helping a student fix a project and ran into a really confusing bug that I went in circles trying to figure out. It's solved, but now I come to the thread to ask this:

Is there any valid reason to put something like a @classmethod decorator on a class's __init__ method? Or any decorator, really? I really thought the interpreter would have had some special stuff in it for making sure those methods didn't get decorators thrown on them.

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4
That makes some sense, thank you.

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4

NinpoEspiritoSanto posted:

Please please learn from anything other than Learn Python the Hard Way. Author doesn't even understand python 3 properly.

I know people had some opinions about Zed Shaw, mostly because he has a lot of opinions that he can't seem to keep his mouth shut about, but what about the book is improper re: python 3? I learned my basics from the Python 2 version and flipped through the third, and at the time nothing stood out to me.

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4
I want to write a traditional console roguelike in Python. Originally I was going to not bother using an actual console and just use libtcod, but the documentation is way worse than it used to be and figuring out event handling is kind of frustrating me - I wanted to do an actual 80x24 console to begin with anyways, the kind of thing you could play remotely over SSH if so inclined. Python has curses built in, but...

quote:

The Windows version of Python doesn’t include the curses module. A ported version called UniCurses is available. You could also try the Console module written by Fredrik Lundh, which doesn’t use the same API as curses but provides cursor-addressable text output and full support for mouse and keyboard input.

I'd like this in theory* to be playable on Windows. Unicurses has kind of inadequate documentation that is just gonna have me look at the C documentation a lot, which isn't great but is livable. The Console project linked is a dead webpage - someoneupdated it to Python 3, but there's no documentation and if I have to dig through the source to understand everything I may as well just use libtcod.

Anyone have a suggestion of what to use, any package suggestions? Or will I just do it in Linux anyways and save letting Windows people play it until I get a webserver going?

(* really I wanna do it through a browser, like how DCSS's webtiles servers work, alongside ssh, but getting an actual playable game first might be a good idea)

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4

Raygereio posted:

Anyone have recommendations for terminal/text UIs?
I've made a script to automate measurements for a multiplexer and want to make it quicker to use (so a user doesn't have to edit the script when they want to change between measuring voltage or resistance, or tweak measurement intervals).
I could make an interface with tkinter, pysimplegui, QT, or whatever, but that feels like it would be to elaborate for the actual functionality it needs to have. I also could bash my head against curses until I get something nice, but that would go against my desire to not spend too much time on it.

I did ask about this earlier (and sadly I don't think the posted ones really solved my problems - I decided to just go with libtcod since it has some useful built-in pathfinding stuff and rather than do essentially an actual tty/ssh connection in-browser I can just squirt the game state to the browser as JSON or w/e) and after looking into them/fiddling for a bit I think Rich and Urwid seem to be the simplest/quickest to get going with - although it's worth noting I didn't do much other than read some documentation and real quickly do some experiments)

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4

CarForumPoster posted:

#1
For your print statements, these two things are the same but one is both easier to read and faster to write.
print("Total distance traveled is:" + str(height1) + " units")
-vs-
print(f"Total distance traveled is: {height1} units")

also this is really good to point out (all of them were good) , just wanted to say I pointed out the existance of f-strings to someone I work on a project with who's not natively a Python programmer and her response was "hell yeah, this is awesome"

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4
I have a student who's interested in using Python to explore cybersecurity/penetration testing/etc. which is a field I don't know much about. Does anyone have any recommendations for books, sites, etc. on the topic - ideally ones aimed at the introductory level? I asked another group I'm in and got two links to dead blogs about Kali Linux, a collection of dead git repos, and some pentesting frameworks with lovely documentation. So, to clarify, I'm looking for real novice-level material - maybe something a 200-level CS student with some Linux background could digest?

e: I've heard good things about Grey Hat Python, and I know that's super old - but Black Hat Python by the same author is semi-recent, would that be an okay start?

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4
It sounds like you've determined Django would be absolute overkill for your needs, but it's worth noting for future reference that a django-admin created barebones project is configured with a sqlite3 database, no muss no fuss.

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4

Gin_Rummy posted:

I have a music synthesizer app I created, which pulls up a GUI off of a single .py file, and I am trying to figure out the best way to port it into a webpage. From what I understand, Flask will take the return values of Python functions and whatnot I feed it then return it to a webpage... but if my app doesn't really have a return value, I can't use Flask, right? Do I need to just rebuild my app entirely in another language like Javascript, or can I use more advanced functionality of Flask/another framework to translate my app?

I mean, depending on what the app is doing, you can just pass the data into a function that does your synthesis stuff, and if it's just creating a sample and storing it on disk or whatever Flask can just return a redirect to whatever page you started at. I'm imagining something like a sequencer/live synthesis, though, and that you'd probably want to just reimplement in JS if you want it to be an actual website... if you're just using Flask because you don't like any of the Python GUI toolkits, though, it can just run a local server and do whatever.

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4

QuarkJets posted:

I thought the whole point of flask was not having to write your app in javascript, have I been led astray?

Flask handles the back end. If you wanna do something fancy on the client ('fancy' meaning anything more than puke out a template and some static files), that's gonna be JavaScript.

Or, you know, something else. Like Brython. (which is... JavaScript when you get down to it)

skull mask mcgee posted:

Lol maybe don’t open your post with “y’all are nuts” when making assertions about a domain you have no knowledge of if you’re looking for a polite response.

:agreed:

If we were talking 'synthesizer' like 'speech synthesizer', just generating samples, a simple web app would be fine. If you're looking to do some live knob-tuning or whatever like you would with a VST or a real-deal instrument, even something like a connection via a socket is gonna be dogshit. Like, it's possible, but...

Gin_Rummy posted:

Also this is mainly a learning exercise for myself. Just cobbling together a solution isn't so much what I'm interested in, as I am really just trying to properly learn to how to code with and implement my code into frameworks.

Good news - if you want, you can still get Flask involved in here. It might be overkill, but maybe you forsee a future where you want to save patches or sequences to the database for later access from another machine?

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4

Gin_Rummy posted:

Definitely both, but emphasis on the former as my primary focus. Sounds like I can develop a bit of back-end development skills by working on the former, though?

I'd focus on one thing at a time - figure out how to do what you want in JavaScript, then think about how to pipe that data from the client to the server to do whatever with it.

Adbot
ADBOT LOVES YOU

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4

alexandriao posted:

Has anyone ever written an interface to SA in python?

It's probably not exactly what you're looking for, but Votefinder (a tool the Mafia community here uses to help run games) has quite a bit of code to download/parse SA posts and reply to certain threads. If you're looking to do something specific and need inspiration, you might want to poke around here.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply