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
cinci zoo sniper
Mar 15, 2013




Yeah the scientific view array-like object viewer is pretty great.

Adbot
ADBOT LOVES YOU

pubic void nullo
May 17, 2002


cinci zoo sniper posted:

Yeah the scientific view array-like object viewer is pretty great.

This works for Pandas just as well in the free version with no scientific mode, too.

cinci zoo sniper
Mar 15, 2013




pubic void nullo posted:

This works for Pandas just as well in the free version with no scientific mode, too.

Oh, looks like that just got extended around the advent of scientific mode, or I otherwise missed it. Either way, my main thing (the only, pretty much) with scientific mode is code cells. It's all I need from Jupyter without the bloat accompanying the latter.

Dominoes
Sep 20, 2007

Pycharm's also an outstanding IDE for web languages (JS/TS/HTML/CSS etc), and with the official plugin, Rust.

Sad Panda
Sep 22, 2004

I'm a Sad Panda.
Is there a way to bulk import a whole subdirectory? I ask because I've got 150ish files in books/, import them all manually and then call them for example using that.

Python code:
    balance = eval(script_name).scrape_balance(driver)
One idea I had is to move all those import statements into their own file and then import that just to make my main file that much shorter.

Sad Panda fucked around with this message at 00:08 on Jul 2, 2018

Wallet
Jun 19, 2006

Dominoes posted:

Pycharm's also an outstanding IDE for web languages (JS/TS/HTML/CSS etc), and with the official plugin, Rust.

Really? I assumed that wouldn't be the case as Jet Brains has a separate JS IDE.

Baby Babbeh
Aug 2, 2005

It's hard to soar with the eagles when you work with Turkeys!!



I wouldn't use it preferentially over the JS IDE if I was doing pure JS but if you're doing a full stack project with Python you can do the frontend stuff in Pycharm and it's actually really seamless and nice.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Wallet posted:

Really? I assumed that wouldn't be the case as Jet Brains has a separate JS IDE.

PyCharm is basically a superset of WebStorm.

Generally speaking, WebStorm gets ahead of PyCharm when they do a release, but then the next of PyCharm catches it up.

huhu
Feb 24, 2006

Sad Panda posted:

Is there a way to bulk import a whole subdirectory? I ask because I've got 150ish files in books/, import them all manually and then call them for example using that.

Python code:
    balance = eval(script_name).scrape_balance(driver)
One idea I had is to move all those import statements into their own file and then import that just to make my main file that much shorter.

Maybe I'm missing something but you could just use the os package and get all the files in a directory and then iterate over them.

cinci zoo sniper
Mar 15, 2013




huhu posted:

Maybe I'm missing something but you could just use the os package and get all the files in a directory and then iterate over them.

Use glob for this.

SurgicalOntologist
Jun 17, 2004

Specifically, pathlib.Path.glob.

Sad Panda
Sep 22, 2004

I'm a Sad Panda.
Thanks for the start.

Python code:
import pathlib
import importlib

books_path = pathlib.Path('books')

for book in pathlib.Path.glob(books_path, '*.py'):
    importlib.import_module(book)
That's what I've got so far, which is almost there. Except this afternoon I need to work on getting book from

books/filename.py
to books.filename

My initial reaction is to convert to a string and manipulate it, but there's probably a smarter way when I read the docs.

cinci zoo sniper
Mar 15, 2013




Sad Panda posted:

Thanks for the start.

Python code:
import pathlib
import importlib

books_path = pathlib.Path('books')

for book in pathlib.Path.glob(books_path, '*.py'):
    importlib.import_module(book)
That's what I've got so far, which is almost there. Except this afternoon I need to work on getting book from

books/filename.py
to books.filename

My initial reaction is to convert to a string and manipulate it, but there's probably a smarter way when I read the docs.

Just use regular glob, https://docs.python.org/3/library/glob.html

duck monster
Dec 15, 2004

This might seem like a crazy-person thing to do, but is it possible to pass an operator by reference.

Im trying to figure a way to create am array of rules that can be used to analyse a musical interval or group of them, so I can go;-
"if note a and be is a rule 1 or a rule 2 but not a rule 3 and is a rule 4 then constraint satisfied"
each rule has a class with a check_constraint(*notes) ie IsSemiTone, IsWholeTone, IsNotAugForth etc and I want to be able to pass in a list of these and and,or,not,xor etc
the idea being is the end user can chose the constraints and then I permutate over a scale and check validity

I'm looking to try and work out the minimum rule sets to generate various types of tonalities. Ie western harmony, chinese scales etc.

Turns brute searching all possible scales isnt expensive. (2 ^ 12)/2 (can cut the search space in half as all scales start on the first note, so position 1 is never 0 )

poo poo, maybe i should just use eval

(also I know you can generate a scale just uaing circle of fifths, but im trying to avoid symetry group type constraints)

duck monster fucked around with this message at 19:35 on Jul 2, 2018

necrotic
Aug 2, 2005
I owe my brother big time for this!
All operators are magic methods, no? Like < is __lt__? Reference those instead perhaps.

There's also the operator library: https://docs.python.org/3.4/library/operator.html

edit: not sure if you can do this for and/or.

Master_Odin
Apr 15, 2010

My spear never misses its mark...

ladies
What exactly would you want users to pass to your function? A multidimensional list of strings that evaluate to functions or Boolean operators?

duck monster
Dec 15, 2004

Master_Odin posted:

What exactly would you want users to pass to your function? A multidimensional list of strings that evaluate to functions or Boolean operators?

Functions and booleans, but the __operator__ seems the way to go

Roargasm
Oct 21, 2010

Hate to sound sleazy
But tease me
I don't want it if it's that easy

Sad Panda posted:

Is there a way to bulk import a whole subdirectory? I ask because I've got 150ish files in books/, import them all manually and then call them for example using that.

Python code:
    balance = eval(script_name).scrape_balance(driver)
One idea I had is to move all those import statements into their own file and then import that just to make my main file that much shorter.

You can create a package of modules as "books" if you create a __init__.py file there. It can import different ways depending on how you do it, one of which is to do all of the import statements in the init file (which will give you the books.file.function that it sounds like you want)

Master_Odin
Apr 15, 2010

My spear never misses its mark...

ladies

duck monster posted:

Functions and booleans, but the __operator__ seems the way to go
That still doesn't really tell me much on what exactly your data structures are or how you're looking to combine them.

You can though use the operator module (or __operator__ magic functions on the classes) and then do what sqlalchemy does and define and_, or_, etc to then combine the functions you're calling into a meaningful way, or decompose it into a minimum set of operations if that's your aim.

mr_package
Jun 13, 2000
Speaking of glob and pathlib: if you wanted to do a case-insensitive comparison on a non-Windows system would you instantiate a PureWindowsPath so you can do Path.match("*.py") or use string compare e.g. Path.name().lower().endswith("*.py")? I think string compare is uglier to read; is using a Windows Path too much of a hack in this context? Does it even matter? (I tend to self-bikeshed a lot).

mr_package fucked around with this message at 21:21 on Jul 3, 2018

necrotic
Aug 2, 2005
I owe my brother big time for this!
I don't think using PureWindowsPath would help here, but I could be wrong. If all you need is the extension to ignore case use glob syntax: *.[pP][yY].

edit: On using PureWindowsPath, the implementation of #match is from the superclass PurePath. Each of the "flavors" has a case-folding method applied to the input, and on Windows it simply "to-lowers" the input. Using that on a Linux system would cause even more issues with case sensitivity!

necrotic fucked around with this message at 21:28 on Jul 3, 2018

mr_package
Jun 13, 2000
Ah ok thanks-- I just did a quick test on macOS and it was working, but it does seem regex is the obvious choice here. I just want to avoid the case where someone names a file .ZIP or whatever and then everything breaks.

necrotic
Aug 2, 2005
I owe my brother big time for this!
MacOS is not Linux and is not case sensitive by default.

teen phone cutie
Jun 18, 2012

last year i rewrote something awful from scratch because i hate myself
I have a pet project that I’ve been hashing out for a while now, and I’ve decided I want to use Flask as my backend.

I don’t know anything about Python, but I do know that flask comes with a built in local server and database. I was recommended in the past to use Postgres as my database, but as of right now I only have experience with MySQL. My question is that I’m wondering if there’s any advantages in using postgres with Flask opposed to MySQL.

(FWIW, I only think I’ll need to GET endpoints, so a framework is probably overkill, but this isn’t a serious project).

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Grump posted:

I have a pet project that I’ve been hashing out for a while now, and I’ve decided I want to use Flask as my backend.

I don’t know anything about Python, but I do know that flask comes with a built in local server and database. I was recommended in the past to use Postgres as my database, but as of right now I only have experience with MySQL. My question is that I’m wondering if there’s any advantages in using postgres with Flask opposed to MySQL.

(FWIW, I only think I’ll need to GET endpoints, so a framework is probably overkill, but this isn’t a serious project).

Flask doesn't know anything about databases, you could write everything to a plain text file it wouldn't know or care. It's like asking if your python script cares if you're using a 144hz monitor.

If you want something that gives you help with databases, you'll need to use Django or use an additional library with Flask. If you're using an ORM, then, from the standpoint of your ORM and your application it doesn't matter which database you're using...postgres or MySQL will both suffice. If you're not using an ORM, then with Django or Flask you just import the correct mysql or postgres library and write your SQL. Neither cares which DB you're using.

Postgres is recommended over MySQL for reasons that mostly don't have anything to do with how you write or use your application and that's even more the case if you're using an ORM.

It is recommended because of all its features beyond basic SQL, like built-in NoSQL support, full ACID compliance, and things beyond features like it being open source without Oracles involvement.

Usually when Flask comes up, I feel compelled to point out that Flask is a great and capable framework, but the reason many people choose it over Django is that it's "lighter weight". This is wrong, Django is capable of being used in the same light weight manner.

There are good reasons to use Flask, but if this is your reason you will want to reconsider.

teen phone cutie
Jun 18, 2012

last year i rewrote something awful from scratch because i hate myself
And an ORM is just a tool that abstracts away the SQL into more functional programming paradigms?

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Basically. Django has one in the box, you use different ORM libraries with Flask.

The Fool
Oct 16, 2003


At work in am receiving a backup of an Sql database, but I will not be getting control of any of the existing infrastructure or front end.

I was thinking about throwing up a quick and dirty Django front end, but have no idea how to set up the orm to handle an existing database.

Is there an accepted best practice? Should I just build out a new table structure that I can import the data into, or is there a better way?

mr_package
Jun 13, 2000

necrotic posted:

MacOS is not Linux and is not case sensitive by default.
On MacOS, Path instances are PosixPath by default.
code:
>>> import pathlib
>>> type(pathlib.Path())
<class 'pathlib.PosixPath'>
>>> pathlib.Path("A.PY").match("*.py")
False
>>> pathlib.PureWindowsPath("A.PY").match("*.py")
True
This case sensitivity extends to files on disk too even if the underlying filesystem isn't e.g. if you loop Path.iterdir() trying match("*.zip") and someone has named their file AWESOME.ZIP it will fail.

mr_package fucked around with this message at 07:07 on Jul 4, 2018

duck monster
Dec 15, 2004

Master_Odin posted:

That still doesn't really tell me much on what exactly your data structures are or how you're looking to combine them.

You can though use the operator module (or __operator__ magic functions on the classes) and then do what sqlalchemy does and define and_, or_, etc to then combine the functions you're calling into a meaningful way, or decompose it into a minimum set of operations if that's your aim.

I ended up taking a really simplistic way of doing it.

OPERATOR_OR = 0
OPERATOR_AND = 1
code:
            r = s.check_constraint(first,second,third)

            if o == OPERATOR_OR:
                result = r or result
            elif o == OPERATOR_AND:
                result = r and result
            else:
                raise("OPERATOR NOT IMPLEMENTED")
So far it all works.
Heres an example of one of my rules;-

code:
class SemisWholesAndNoConsecutiveSemis(SelectionBase):
    def __init__(self,scale):
        super().__init__(scale,[(OPERATOR_OR,WholeTone),(OPERATOR_OR,SemiTone),(OPERATOR_AND,NoConsecutiveSemiTones)])
And for all notes in the regular western chromatic scale, it finds these (Note, all scale modes, it treats same as root scale, because really, just the same scale rotated around a bit)
code:
iterate_all_notes(SemisWholesAndNoConsecutiveSemis)
['C5', 'D5', 'E5', 'F#5', 'G#5', 'A#5']
['C5', 'D5', 'E5', 'F#5', 'G#5', 'A5', 'B5']
['C5', 'D5', 'E5', 'F#5', 'G5', 'A5', 'B5']
['C5', 'D5', 'D#5', 'F5', 'F#5', 'G#5', 'A5', 'B5']
Count:2048
Its not *that* smart though. It finds C Lydian, and then ignores the Major or Minor modes. So indeed it found the Major, but not in its Ionian mode, and it finds a C augmented lydian, but not the C melodic minor.

But ultimately, it correctly identifies that the only scale where every note is a whole or halftone and there are no consecutive semitones, are the whole tone scale , wholetone-halftone scale , major scale and melodic minor scales, and of course their modes.

And if we chose to ignore Harmonic minor, I *think* those scales encompass pretty much everything in traditional western tonality in just 3 simple rules. Now to find a minimal set of rules that can include the Harmonic minor scales and a few of the less common scales of pre "everyone started writing crazy poo poo" era western canon up till the romantic era..

duck monster fucked around with this message at 21:26 on Jul 4, 2018

Data Graham
Dec 28, 2009

📈📊🍪😋



The Fool posted:

At work in am receiving a backup of an Sql database, but I will not be getting control of any of the existing infrastructure or front end.

I was thinking about throwing up a quick and dirty Django front end, but have no idea how to set up the orm to handle an existing database.

Is there an accepted best practice? Should I just build out a new table structure that I can import the data into, or is there a better way?

Modeling an existing table schema in Django's ORM isn't too much of a hassle. Just specify db_table and db_column if you don't want to rename anything. There shouldn't be anything in the schema it can't deal with, or if you do it might not be important anyway?

Hed
Mar 31, 2004

Fun Shoe

The Fool posted:

At work in am receiving a backup of an Sql database, but I will not be getting control of any of the existing infrastructure or front end.

I was thinking about throwing up a quick and dirty Django front end, but have no idea how to set up the orm to handle an existing database.

Is there an accepted best practice? Should I just build out a new table structure that I can import the data into, or is there a better way?

You want Django introspection. It will build out the models based on the existing table structure.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

I'm on mobile right now so I'm not looking for it, but I feel like there's a page in the Django docs detailing exactly how to do this.

necrotic
Aug 2, 2005
I owe my brother big time for this!

mr_package posted:

On MacOS, Path instances are PosixPath by default.
code:
>>> import pathlib
>>> type(pathlib.Path())
<class 'pathlib.PosixPath'>
>>> pathlib.Path("A.PY").match("*.py")
False
>>> pathlib.PureWindowsPath("A.PY").match("*.py")
True
This case sensitivity extends to files on disk too even if the underlying filesystem isn't e.g. if you loop Path.iterdir() trying match("*.zip") and someone has named their file AWESOME.ZIP it will fail.

That's pretty nutty... the OSX file system is case insensitve, I'd expect my Path/Glob library to treat pretend access the same. The Windows implementation does the downcase to emulate this, I assumed they did the same for OSX.

teen phone cutie
Jun 18, 2012

last year i rewrote something awful from scratch because i hate myself

Thermopyle posted:

Basically. Django has one in the box, you use different ORM libraries with Flask.

I ended up going with Django.

Getting it set up on Windows Subsystem Linux was kind of a pain but not terrible. I’m probably going to write up instructions if anyone else would be interested in that

duck monster
Dec 15, 2004

Grump posted:

I ended up going with Django.

Getting it set up on Windows Subsystem Linux was kind of a pain but not terrible. I’m probably going to write up instructions if anyone else would be interested in that

wouldnt it work just the same as regular ubuntu, or does Windowlinux's hilariously borked network stack preclude that?

teen phone cutie
Jun 18, 2012

last year i rewrote something awful from scratch because i hate myself
Yeah mostly the same but there’s some other dumb stuff that isn’t apparently obvious, such as creating a symlink between your windows and linux directories, so you can open your files in a text editor

NtotheTC
Dec 31, 2007


WSL support is huge but at the moment file permissions not transferring and the lack of systemd support meant I couldn't use it for development

Boris Galerkin
Dec 17, 2011

I don't understand why I can't harass people online. Seriously, somebody please explain why I shouldn't be allowed to stalk others on social media!
I'm trying to play around with __getattr__ and __setattr__ so that I can do something like the following:

code:
class MyClass:
    def __init__(self):
        self._whatever = OtherClass()

    def __getattr__(self, k):
        # if self._whatever (OtherClass) has k then return self._whatever.k
        # elif self has k then return self.k
        # else raise error

    def __setattr__(self, k, v):
        # if self._whatever has k then set self._whatever.k = v
        # else self.k = v if and only if self._whatever does not have k
I am getting recursion errors the moment I add the __setattr__ method and no amount of searching has given me a clear answer on how to fix this.

I found this stackoverflow post and it's basically the same problem I am having. The help responses given there are extremely cryptic and not helpful at all. One person wrote some paragraphs explaining what was happening but nobody ever actually answers the question

quote:

So how would I go about this? I want precedence over the self implemented descriptors instead of always serving the self._field entries. – Yonathan Aug 30 '17 at 20:21

e: I would like to avoid implementing @property and @setters for everything.

Boris Galerkin fucked around with this message at 11:47 on Jul 6, 2018

Adbot
ADBOT LOVES YOU

Mrenda
Mar 14, 2012
Is there a particular setup I should have for developing with Python on windows?

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