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.
 
  • Locked thread
Shear Modulus
Jun 9, 2010



I don't have much knowledge of common scientific computing packages beyond Numpy, Scipy, etc. Is there a package with a good implementation of some statistical model building algorithms like (for example) LASSO? Or should I just learn how to call R from my Python code?

Adbot
ADBOT LOVES YOU

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

tractor fanatic posted:

is in will test for string equality, and not string identity, right? I can do if my_string is in [list of strings read from a file] and it will work?

If by if a is in b: you mean if a in b:, then yes, it's equality, not identity. a is in b is a syntax error.

rvm
May 6, 2013

Shear Modulus posted:

I don't have much knowledge of common scientific computing packages beyond Numpy, Scipy, etc. Is there a package with a good implementation of some statistical model building algorithms like (for example) LASSO? Or should I just learn how to call R from my Python code?

Try pandas, statsmodels and sklearn.

Mrs. Wynand
Nov 23, 2002

DLT 4EVA
(What follows is a OOP-patterns / engineering heavy post smacking of architecture astronaucy... apologies in advance)


So, I'm starting a new greenfield project (:woop: it is truly best in life) and this time around I'd like to try something a little different and stay away from ActiveRecord-style orm (e.g. django.db.model). What kinda bugs me about them is that your domain model becomes irreversibly tied to the storage layer, and although it's not likely we'll swap it all out for a totally different storage engine on a whim, it encourages a number of things that I am not terribly happy with - e.g. it is never clear what the true public interface of a domain model is that has to be actively maintained - you just sort of have to keep the whole django.db.model.Base working at all times. It also makes this nasty to mock out for testing and other stuff. Like, it's not the worst thing in the world, but I'd like to see how life is without it and keep the storage layer completely decoupled. (also all these ActiveRecord type mappers rely on __metaclass__ which loving is the worst thing in the python world - it's action at a distance and it's impossible to compose, i'll just take class decorators thank you very much).


So first of off - is there like a name or guide for this sort of separation? I hear it talked about quite a bit but never with quite the same name. Is it data access object? That seems mostly associated with the Java/.NET world, but it does seem to be an actual general pattern, not just a java/.net library.

Second, regardless of what it's called, the idea is that for any given domain model you have a corresponding storage class that takes care of persistence and retrieval (the "data access" i suppose!), right?

Python code:
# ActiveRecord style:
butts = Butt.top_butts(by="size")
largest_butt = butts[0]
largest_butt.wiggle() # possibly calls butt.save() internally

# DAO style?
butt_storage = DBButtDAO(connection=conn)
largest_butt = butt_storage.top_butts(by="size")[0]
largest_butt.wiggle()
butt_storage.persist(largest_butt])
... is that basically the idea?

What sort of worries me is that although the DAO one looks "neater" and all, eventually you need to work with storage-layer-specific objects more directly to get things done efficiently - e.g. composing django.db.model.QuerySet objects (which is quite useful!) or running update() on it. When that happens is the idea to just contain all the things you specifically need doing with those store-specific objects inside the non-store-specific public interface of the DAO object? Like, basically your DAO would eventually start looking like, for example, an actual outward facing API - stuff you'd put in your API "controllers" would end up in the DAO instead, with your actual API controllers becoming an extremely thin wrapper around them?

That... would probably be ok I guess, I'd just like to get some validation that I'm on the right track though. It also looks like it's possible that if most of your complexity is actually about storage and retrieval you'll end up with some very anemic domain model classes and very fat DAO classes, but again... that's probably fine isn't it? It's merely reflecting the reality of your problem.

So in that case, I further wonder if it would be OK to actually use, say, SQLALchemy's declarative data mapper inside the DAO class, even though the declarative extension appears to be specifically meant for ActiveRecord style persistence modeling. So there would be a non-sql-specific DAO interface, but the actual implementation could multiple-inherit from both it and the sql-specific declarative base (well, the bloody __metaclass__ might make that a pain, but that's ok, I can just use the non-declarative explicit mapping, not a huge prob). I'd end up with a class that is (not has!) both a DAO interface and an ActiveRecord-mapping - which should be fine as long as the AR bits don't bleed into the public facing DAO ones. Or is this just asking for trouble?

Haystack
Jan 23, 2005





I don't think that there's anything wrong with creating your own data access layer on top of another ORM. However, it's best to approach such things as automation ("I frequently need to see what the biggest butts are") rather than insulating yourself from the database ("I'm going to write an entire generalized system for posing questions to my ORM"). Otherwise you will very quickly reach the point where you're just replicating what your database and ORM does, but worse.

For reference, here's how SQLalchemy would handle your example.

Python code:
largest_butt = conn.query(DBButt).order_by(DBButt.size).first()
largest_butt.wiggle()
conn.add(largest_butt)
conn.commit(largest_butt)
Also, I would like to point out that SQLalchemy's ORM doesn't use an active record pattern. It uses a unit of work pattern. See this and this for reference on the differnce. It's not a huge difference in your case – django uses magic to keep the database up to date whereas sqlalchemy uses slightly less magic to keep an internal registry consistent – but it's worth knowing the difference.

Haystack fucked around with this message at 21:49 on Nov 5, 2013

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
Speaking of SQLAlchemy...

I am about to start an app in python that will be calling stored procedures on an MSSQL database. After looking around a bit, I think SQLAlchemy is probably the right way to connect / call, but I'd love to hear any alternate solutions or gotchas if anyone has done this before.

Mrs. Wynand
Nov 23, 2002

DLT 4EVA

Haystack posted:

I don't think that there's anything wrong with creating your own data access layer on top of another ORM. However, it's best to approach such things as automation ("I frequently need to see what the biggest butts are") rather than insulating yourself from the database ("I'm going to write an entire generalized system for posing questions to my ORM"). Otherwise you will very quickly reach the point where you're just replicating what your database and ORM does, but worse.

Ok that makes sense - yeah, slowly reinveting a (lovely) ORM is exactly the kind of thing I was worrying about.

quote:

For reference, here's how SQLalchemy would handle your example.

Python code:
largest_butt = conn.query(DBButt).order_by(DBButt.size).first()
largest_butt.wiggle()
conn.add(largest_butt)
conn.commit(largest_butt)

Now, would I start out by just calling the SQLAlchemy ORM mapped classes like that directly in the consumer? Or should I contain the above code inside a public API (domain model or just access lib)? Like, you were saying to think of it as shortcuts - so would this be what I extract into a shortcut? Or should I only bother doing that when I actually need it more than once? If it's not done everywhere it sort of strikes me as having many of the problems I was complaining about above - i.e. the real public API that needs long term support is either unclear or very very large and spread out everywhere.

quote:

Also, I would like to point out that SQLalchemy's ORM doesn't use an active record pattern. It uses a unit of work pattern. See this and this for reference on the differnce. It's not a huge difference in your case – django uses magic to keep the database up to date whereas sqlalchemy uses slightly less magic to keep an internal registry consistent – but it's worth knowing the difference.
Yes of course - I should probably have been more precise. It certainly doesn't take long to run into the limitations of not having a unit of work across which to have consistent identities with real ActiveRecords.

Mrs. Wynand
Nov 23, 2002

DLT 4EVA

Lumpy posted:

Speaking of SQLAlchemy...

I am about to start an app in python that will be calling stored procedures on an MSSQL database. After looking around a bit, I think SQLAlchemy is probably the right way to connect / call, but I'd love to hear any alternate solutions or gotchas if anyone has done this before.

I've never had to specifically look into MSSQL libraries in Python, but I mean, generally speaking, SQLAlchemy is just such a large established project - it's the envy of so many other languages, it seems unlikely there's something remotely equivalent, let alone better out there. It still boggles the mind that Django chose to roll their own ORM instead of building on top of SQLA (though apparently SQLA was a little more persnickety during Django's formative years). Sort of embarrassing that Rails has since managed to "catch up" (sorta) with ActiveRelation, which, I mean, it ain't SQLAlchemy, but at least they aren't still doing regex on sql strings which I have deifnitely still seen around in a few god-forsaken corners of the django.db.model code... :psyduck:

BeefofAges
Jun 5, 2004

Cry 'Havoc!', and let slip the cows of war.

I've used SQLAlchemy with MSSQL and it works just fine. If you're running your code on Linux you might have to do some fiddling with FreeTDS, but otherwise it shouldn't be too painful.

SurgicalOntologist
Jun 17, 2004

Okay, which one of you gave the talk "Become a logging expert in 30 minutes"?

Python code:
if debug:
    LOGGER.debug('Has stairs in their house: %r',
                 is_protected)
Edit to avoid double-posting:
Is pygame reliable? Whatever's linked on pip gets a 404, and if I grab it from the website or bitbucket I can't get it to pass its tests, and if I install it anyway, PyCharm can't seem to index it.

SurgicalOntologist fucked around with this message at 19:04 on Nov 6, 2013

Thermopyle
Jul 1, 2003

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

If I have a function that is getting too long, I'll split out functions that are just used in that one place. Sometimes I'll just nest the functions, sometimes I'll refactor it all in to a class with multiple methods, sometimes I'll just have multiple module-level functions.

As far as I can tell, there's no technical downside to any of these methods, but I think the fact that I don't have any clear preference on the methods means that I'm not very consistent in which method I use.

Which do you prefer?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
If it relies on scope, make it nest. If it doesn't, put it as a top-level function.

If it doesn't rely on self, never put it in the class itself.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

SurgicalOntologist posted:

Edit to avoid double-posting:

Edit to avoid thread readers actually seeing the question. I don't think there's anything wrong with double-posting, but if there is, I guess we'll find out soon!

SurgicalOntologist posted:

Is pygame reliable?

No.

Ireland Sucks
May 16, 2004

SurgicalOntologist posted:

Is pygame reliable? Whatever's linked on pip gets a 404, and if I grab it from the website or bitbucket I can't get it to pass its tests, and if I install it anyway, PyCharm can't seem to index it.

I know 'it works for me' replies are usually horrible, but since that seems to be what you are asking, I've had no problems with it on Windows (using the py 3.2 version). I'm not sure i've run the tests though.

Thermopyle
Jul 1, 2003

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

I wish one of you smart, experienced motherfuckers would get off your rear end and make a good python game framework already. I hate having to tell newbies that their options aren't that great.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
I actually tried, but I gave up. I never felt comfortable with Python for games, and the redistributability issue is a giant one.

Nowadays I'd recommend that people just use HTML5, JavaScript, and WebGL/<canvas>. It's easier to get started with than Python, to be honest, you can reach a lot more people that way, the tooling and dev environment are much better than Python will ever see, and JavaScript isn't that bad as long as you stick "use strict"; at the top of your script.

Jewel and I have been going back and forth on Skype, and she's been inspiring me to play around with this stuff more.

Simple particle physics: http://magcius.github.io/farticle.js/farticle.html
Simple tile-based renderer: http://magcius.github.io/fartile.js/fartile.html

Riot Bimbo
Dec 28, 2006


I don't know if it's okay to ask dumb, simple questions relating to code here, but I've spent the last five or so years desperately trying to forget my never-once-very-developed coding knowledge. I had limited experience in c++ and I learned a year's worth of java coding in highschool. That's mostly gone, so I've been using codecademy's python tutorials to sort of re-establish some forgotten coding principles. I'm not entirely sure how long I'm going to stay with python, but I do enjoy coding with it.

I'm not asking anybody to do my homework, but I'm stumped as to what they want in this particular lesson, and it's sad but I actually don't know enough about the problem I'm having to google help for it.

I have a problem where I'm supposed to take the data inside two dictionaries, and multiply them. The conciet of the lesson is that I'm supposed to multiply the 'stock' of my fruit and veggies by their cost for a total potential profit. The website/interpreter keeps spitting back that I'm not returning the right numbers but everything looks right to me, so I'm assuming it wants me to add all of it together for a grand total.

No matter what, the program is quite small and is as follows:
This is all python 2.7 as it's what codecademy.com opted to use.
code:
prices = {
    "banana": 4,
    "apple": 2,
    "orange": 1.5,
    "pear": 3
}
    
stock = {
    "banana": 6,
    "apple": 0,
    "orange": 32,
    "pear": 15
}

for i in prices:
    print i
    print prices[i]*stock[i]
The for loop is the only thing I've actually written, and it returns accurate values, as seen here:

code:
orange
48.0
pear
45
banana
24
apple
0
None
The interpreter itself returns no errors, but codecademy is freaking out and not letting me continue. Like I said I'm guessing they want all of the dictionary values combined, or at least the sub-totals combined, but they were nice enough to completely neglect to explain how to do any such task, and every attempt I make causes python to spit errors.

If these threads aren't for this kind of assistance, my apologies but since I'm learning this on my own and admittedly no longer know people who give a poo poo about coding, I have to look/ask somewhere.

evilentity
Jun 25, 2010

hemophilia posted:

I have a problem where I'm supposed to take the data inside two dictionaries, and multiply them. The conciet of the lesson is that I'm supposed to multiply the 'stock' of my fruit and veggies by their cost for a total potential profit. The website/interpreter keeps spitting back that I'm not returning the right numbers but everything looks right to me, so I'm assuming it wants me to add all of it together for a grand total.

print is not return.

Riot Bimbo
Dec 28, 2006


evilentity posted:

print is not return.

I'm aware! The exercise just wants me to use print, and not return, to display the values.

AlexG
Jul 15, 2004
If you can't solve a problem with gaffer tape, it's probably insoluble anyway.

hemophilia posted:

I have a problem where I'm supposed to take the data inside two dictionaries, and multiply them. The conciet of the lesson is that I'm supposed to multiply the 'stock' of my fruit and veggies by their cost for a total potential profit. The website/interpreter keeps spitting back that I'm not returning the right numbers but everything looks right to me, so I'm assuming it wants me to add all of it together for a grand total.

The interpreter itself returns no errors, but codecademy is freaking out and not letting me continue. Like I said I'm guessing they want all of the dictionary values combined, or at least the sub-totals combined, but they were nice enough to completely neglect to explain how to do any such task, and every attempt I make causes python to spit errors.

I'm guessing this is the "Something of Value" chapter of "A Day at the Supermarket". The instructions are: "Loop through your dictionaries in order to figure out how much money you would make if you sold all of the food in stock. Print that value into the console!" So they want you to print that value, and just that value - the total amount. Currently, you are printing the per-item expected profit (plus some item names) but not the total of these.

So the question is, how do you come up with the grand total? There are a few ways to do this. Probably the best way forward for you is to figure out how to maintain a running total as you loop through the dictionary. In the end, this will be the grand total, because you will have added everything up. Then you print it.

Does this help?

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord
Reading through codecademy I feel like they really messed this up. Because I can see the idea of a running total being a pretty big step compared to the other stuff they present as exercises. It looks harder than anything they tell you to do when they really introduce for loops later at chapter 14. So yeah, don't get discouraged by this poo poo mr ponyavatar.

Riot Bimbo
Dec 28, 2006


AlexG posted:

I'm guessing this is the "Something of Value" chapter of "A Day at the Supermarket". The instructions are: "Loop through your dictionaries in order to figure out how much money you would make if you sold all of the food in stock. Print that value into the console!" So they want you to print that value, and just that value - the total amount. Currently, you are printing the per-item expected profit (plus some item names) but not the total of these.

So the question is, how do you come up with the grand total? There are a few ways to do this. Probably the best way forward for you is to figure out how to maintain a running total as you loop through the dictionary. In the end, this will be the grand total, because you will have added everything up. Then you print it.

Does this help?

I think this should help quite a bit, thank you.

edit: this helped completely, thanks again

Symbolic Butt posted:

Reading through codecademy I feel like they really messed this up. Because I can see the idea of a running total being a pretty big step compared to the other stuff they present as exercises. It looks harder than anything they tell you to do when they really introduce for loops later at chapter 14. So yeah, don't get discouraged by this poo poo mr ponyavatar.

I'm trying not to let it bother me, but in the last few chapters they have really been amping up what you do with increasingly sparse explanation. That might be fine if they werent introducing new concepts, but they are. Also, this is not related at all, but I hate my ponytar. Some dude lurks the eve thread and dispenses pony and homestuck avatars at his pleasure. I was quite happy to never have an avatar, but such is the punishment for liking and discussing Eve I guess.

Riot Bimbo fucked around with this message at 17:08 on Nov 7, 2013

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Thermopyle posted:

I wish one of you smart, experienced motherfuckers would get off your rear end and make a good python game framework already. I hate having to tell newbies that their options aren't that great.

http://pyopengl.sourceforge.net/ what more do you need :v:*

*I don't know because (without getting into my relative intelligence or lack thereof) I'm not experienced enough :blush:

Thermopyle
Jul 1, 2003

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

hemophilia posted:

I think this should help quite a bit, thank you.

edit: this helped completely, thanks again


I'm trying not to let it bother me, but in the last few chapters they have really been amping up what you do with increasingly sparse explanation. That might be fine if they werent introducing new concepts, but they are. Also, this is not related at all, but I hate my ponytar. Some dude lurks the eve thread and dispenses pony and homestuck avatars at his pleasure. I was quite happy to never have an avatar, but such is the punishment for liking and discussing Eve I guess.

Just in case you weren't aware and wanted to use them instead or as supplements to what you're doing, this thread normally recommends Think Python and Learn Python the Hard Way for people to learn from.

Riot Bimbo
Dec 28, 2006


Thermopyle posted:

Just in case you weren't aware and wanted to use them instead or as supplements to what you're doing, this thread normally recommends Think Python and Learn Python the Hard Way for people to learn from.

I had largely started into this as a way to relearn concepts I'd learned in other languages. "Oh yeah, that's how a function works, that's how to construct a class" sort of stuff, but as I'm going along in python, the more I enjoy it, so thanks, i'll be bookmarking these resources.

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord
Ok this is more like one of those empty "what's the usual or at least your style in this kinda thing" questions:

This is a thing that I used to do a lot until recently, I'm like searching through different paths using different functions at different steps and situations:

Python code:
def step23(some_array, b, c):
    # do stuff
    if butts:
       return butt_step(some_array, k, w)
    else:
       return not_butt_step(some_array, s, r)
But sometimes in the middle of the steps I put some assertions

Python code:
def butt_step:
    assert some_array == something(k)
    #keep doing stuff
So that I can catch those AssertionError exceptions and start again with some other path. This worked pretty well but then it dawned on me that those aren't really "exceptional cases" and I shouldn't be using exceptions like that. Because it's expected that some paths will inevitably end up breaking the conditions of those assertions, my objective is to find and return the paths that went through the end.

So I just started using a sentinel value like -1 instead.

Python code:
def butt_step:
    if some_array == something(k):
        return -1
But this doesn't end up being as effective to me because I need to continuously check around the functions for those returned -1s. What's your usual take on these cases? Is there some specific python idiom regarding sentinel values/exceptions? I feel like I'm missing some obvious sensible thing to do here.

Mrs. Wynand
Nov 23, 2002

DLT 4EVA

Thermopyle posted:

I wish one of you smart, experienced motherfuckers would get off your rear end and make a good python game framework already. I hate having to tell newbies that their options aren't that great.

I liked Panda3D quite a bit. But then I tried Unity and I mean, sure it isn't python, but C# isn't that bad, and it just blows it out of the water. Plus there is no question about people making serious and successful games with Unity and the company and their support are going to be around for a while, whereas Panda was a half-hearted Disney side-project to pump out some shovelware and is now only alive thanks to a handful of OSS contributors.

Edison was a dick
Apr 3, 2010

direct current :roboluv: only

Symbolic Butt posted:

But sometimes in the middle of the steps I put some assertions

Python code:
def butt_step:
    assert some_array == something(k)
    #keep doing stuff
So that I can catch those AssertionError exceptions and start again with some other path.

You should really avoid using assert for this, it's not for flow control, it's for checking internal logic. If you run python with optimisation it will remove assert statements, on the assumption that you've tested that it works first.

I would suggest you either use the exceptions that cause it to be an incorrect path, or you raise your own exception class if the condition is false.

ahmeni
May 1, 2005

It's one continuous form where hardware and software function in perfect unison, creating a new generation of iPhone that's better by any measure.
Grimey Drawer

Thermopyle posted:

I wish one of you smart, experienced motherfuckers would get off your rear end and make a good python game framework already. I hate having to tell newbies that their options aren't that great.

Either someone will have to build Python bindings for Unity via some sort of IronPython wizardry or someone will have to build a cross-platform compatible game library that runs a Python engine on mobile platforms. Either way that's a lot of work.

Riot Bimbo
Dec 28, 2006


I'm just throwing this out there, because I'm loving python, but a lot of the math and abstracted concepts I mastedered while learning java back in 2008, are rusty at best, and while I'm sure it's all there, I'm still struggling here to recall those principles and as a result I am continually getting errors and other issues.

I simply can't afford to go to school, and I'm trying to use my limited, for lack of a beter word, intellect to auto-didact through this, but I need a guide who can set aside even a little bit of time to help me get through this. I am determined to re-learn coding as it was my first passion. I've chosen python to do this, anyone who has taken a psych 101 course knows people have different learning styles, and I thrive in an environment with limited lecturing and tons of hands-on experience. Gleaning data from academic books on the subjects is tough because they either want you to anabdon what ou already know and learn it their way. I know there are a million ways to skin a cat in most languages, so this is incredibly frustrating.

Mind, I'm not incapable of learning by books, and I'm not afraid to ask for help occasionally in gere, but I don't want to flood the catch-all python thread with hilarious newbie questions, or earn their ire.

Let me cut to the chase, is anyone willing to be a part time tutor for me? That's not as much of a commitment as it sounds. I'm asking for a buddy I can PM or maybe talk to on external programs that I can hit up for questions as I embark on this journey. After this post I'm happy to take discussion to PM or elsewhere, but maybe it's just a confidence thing, but learning this on my own is daunting and I learn best in an evnironment where I have a real teacher that's able to read and adapt to what I'm trying to do, rather than skimming indexes on my own in in textbooks.

You'll note from my earlier posts that I use codecademy right now. This is because the interactive environment and side-by-side lessons most closely resembles a classroom environment that I would otherwise get a school (which I can't afford.)

This is a pretty insane request but I know there are people out there with a passion for this stuff who are happy to help. If you're one of theses people, shoot me a PM. Again I'm not the type to ask for you to help me with my homework. I don't want people helping me complete code that I don't get. I'd just like to meet someone who can see a problem I'm having, and explain the logic of the problem to the point where I can find my own solutions.

Am I out of line asking this in this thread? I'm not a bookwork at heart, and having experienced persons delivering help as-needed is my ideal learning method.

I'm not sure I can do in return, but with your help and tutelage, whoever stepped up, I would be willing to do some of the more menial tasks in python for your project as far as my ability allows, which is zero right now.

I hate to beg but I am determined to go down this path again and I'd be willing to meet the terms of anyone who would be willing to help me as a tutor.

Thermopyle
Jul 1, 2003

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

Why don't you just try asking your questions in this thread? We're pretty beginner friendly here.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

hemophilia posted:

Mind, I'm not incapable of learning by books, and I'm not afraid to ask for help occasionally in gere, but I don't want to flood the catch-all python thread with hilarious newbie questions, or earn their ire.
This isn't circa-2003 Slashdot. We love newbies here. That said, if you're looking for mentorship, the IT megathread in SH/SC just put together a LinkedIn group for people looking to pair up mentors/newbies, so something like that might not be totally out of line for CoC either.

Riot Bimbo
Dec 28, 2006


Thermopyle posted:

Why don't you just try asking your questions in this thread? We're pretty beginner friendly here.

I'll do that. I'm used to some pretty insane snark and elitism when newbies ask for help in a lot of development communities, so I was apprehensive about flooding (well, not flooding) but posting numerous newbie coding problems eliciting a bunch of :shobon: and :smug: responses, as is the case in many places.


Misogynist posted:

This isn't circa-2003 Slashdot. We love newbies here. That said, if you're looking for mentorship, the IT megathread in SH/SC just put together a LinkedIn group for people looking to pair up mentors/newbies, so something like that might not be totally out of line for CoC either.

I'll also check this out.

I really want to grasp programming again, because it was a passion of mine as a teen and I want to get it back before my mind settles in and this stuff becomes increasingly difficult to learn.

coaxmetal
Oct 21, 2010

I flamed me own dad

hemophilia posted:

I'll do that. I'm used to some pretty insane snark and elitism when newbies ask for help in a lot of development communities, so I was apprehensive about flooding (well, not flooding) but posting numerous newbie coding problems eliciting a bunch of :shobon: and :smug: responses, as is the case in many places.


I'll also check this out.

I really want to grasp programming again, because it was a passion of mine as a teen and I want to get it back before my mind settles in and this stuff becomes increasingly difficult to learn.

please.... fix your avatar though. unless someone keeps buying that one for you.

BigRedDot
Mar 6, 2008

Thermopyle posted:

If I have a function that is getting too long, I'll split out functions that are just used in that one place. Sometimes I'll just nest the functions, sometimes I'll refactor it all in to a class with multiple methods, sometimes I'll just have multiple module-level functions.

As far as I can tell, there's no technical downside to any of these methods, but I think the fact that I don't have any clear preference on the methods means that I'm not very consistent in which method I use.

Which do you prefer?
Well, there are some differences. If you nest the functions, you will pay for the cost of the function definition every time the outer function executes. You're also technically creating a closure, but if you are not returning the inner functions you probably won't know or care, although the closure scope lookup inside the closure may have slightly different performance characteristics than a normal function.

A class lets you encapsulate the data and provides implicit access to it through self, as you surely know. Using a class also allows your functions to plug into python syntax via special methods. These things can be nice, but just be aware that object size mirrors dictionary growth rates, which are quite aggressive. If you are creating a gazillion of these objects, consider using __slots__ for memory and performance optimization.

Functions in a module is the simplest and most straightforward. In the absence of any other considerations this is probably what I would start with.

Riot Bimbo
Dec 28, 2006


Ronald Raiden posted:

please.... fix your avatar though. unless someone keeps buying that one for you.

I sincerely can't afford to drop the pittance to change it. This is hardly the place to say this, and don't take this as a beg because I care way less than everyone who is subject to seeing it, but if you want to and have the means change it, you could give me a big red text avatar calling me a retard for all I care, but I personally am not in a financial situation to spend money on avatar changes.

Dominoes
Sep 20, 2007

More noob questions, less e/n.

tef
May 30, 2004

-> some l-system crap ->

hemophilia posted:

I hate to beg but I am determined to go down this path again and I'd be willing to meet the terms of anyone who would be willing to help me as a tutor.

Tutoring is a lot to ask for, but in the meantime just ask the questions and someone here will usually give you an answer.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



ahmeni posted:

Either someone will have to build Python bindings for Unity via some sort of IronPython wizardry or someone will have to build a cross-platform compatible game library that runs a Python engine on mobile platforms. Either way that's a lot of work.

I'm not sure it'd be so hard to minimally get running, provided you have Unity and the IronPython assemblies handy. Setting up a DLR environment and pointing it at a Python script is actually ~5-10 lines in C# which my 30 seconds of googling suggests would be totally doable from a default Unity install since it apparently just uses Mono under the hood. I might try it this weekend if I have time, but it's looking like I won't :\

Adbot
ADBOT LOVES YOU

Pollyanna
Mar 5, 2005

Milk's on them.


Flask has a particular set of instructions for rendering a webpage. For example, this is the code you would use for an about page:

Python code:
@app.route('/about')
def about():
  return render_template('about.html')
I am extremely lazy, however, and it would be nice if I could write a function that added a page for me given a URL pattern, a page name, and a reference to an HTML file, like so:

Python code:
def addpage(pattern, name, src):

    page = name

    @app.route(pattern)
    def page():
        return render_template(src)
I have a feeling that this wouldn't work, though. First off, I'm trying to use the name parameter to define a new function within addpage(). However, PyCharm tells me "local variable page is not used" on line 2 and "local function page() is not used" on line 5. Why does this error occur?

And is this even doable, anyway? Can I define a function within a function like that?

  • Locked thread