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
amethystdragon
Sep 14, 2019

Deadite posted:

I’m pretty new to python, and I didn’t think to just download the code and import it that way.

I’m used to programming in SAS, so having to find packages to accomplish tasks is hard to get the hang of. I keep thinking there must be a way to do everything in vanilla python and that’s the wrong way to think about creating programs it seems

Python is great about having a library for everything. There's a joke you can import anything you need in Python.
Also means you need to import to do most things as common functions like HTTP, PDF, databases, etc. get abstracted away.

It could be done in code using the base python code but would be more complicated then just getting the source code.
IMO if someone has done the work previously, best to be lazy and use that. No sense in reinventing the wheel twice.

Adbot
ADBOT LOVES YOU

unpacked robinhood
Feb 18, 2013

by Fluffdaddy
I'd like to do realtime reporting on thousands of network tasks being processed, possibly using websockets to push updates to a browser. They're part of a big batch i need to keep tabs on.

I'm not sure how to reason about this.

Reading about concurrent.futures made me want to use those, but I'm not sure how to tally updates on the current state of the system, considering each task can have a few states (likely common stuff like "pending", "failed" and "done")

How can a simple network task inform the rest of the system of its state in an elegant way ? Maybe have each task update its state to a redis instance, but then I'd need something to watch over Redis and push updates when they happen (avoiding polling would be nice).

Hemingway To Go!
Nov 10, 2008

im stupider then dog shit, i dont give a shit, and i dont give a fuck, and i will never shut the fuck up, and i'll always Respect my enemys.
- ernest hemingway
So no matter what I do, PyCharm gives me the error "AttributeError: 'InputHookManager' object has no attribute '_stdin_file'" whenever I try to import from a sublibrary like with "import matplotlib.pyplot as plt" or "from scipy.signal import argrelextrema"

Turns out I don't need those libraries in particular right now but maybe I will in the future. I tried some google searchs, including the one that changed some global variables or updated pycharm, and they don't seem to be working (and again it's not exclusive to matplotlib...). Any suggestions?

Thermopyle
Jul 1, 2003

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

Hemingway To Go! posted:

So no matter what I do, PyCharm gives me the error "AttributeError: 'InputHookManager' object has no attribute '_stdin_file'" whenever I try to import from a sublibrary like with "import matplotlib.pyplot as plt" or "from scipy.signal import argrelextrema"

Turns out I don't need those libraries in particular right now but maybe I will in the future. I tried some google searchs, including the one that changed some global variables or updated pycharm, and they don't seem to be working (and again it's not exclusive to matplotlib...). Any suggestions?

Just to be clear, is it PyCharm or Python giving you this error? (I only ask because I don't know your experience level and newbies often have a hard time distinguishing between their IDE and the programming language)

Thermopyle
Jul 1, 2003

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

New PyCharm out today. Best features for me: interactive widgets in jupyter notebooks, TypedDict and Literal support, completion for when you're typing file paths into strings.

Hemingway To Go!
Nov 10, 2008

im stupider then dog shit, i dont give a shit, and i dont give a fuck, and i will never shut the fuck up, and i'll always Respect my enemys.
- ernest hemingway

Thermopyle posted:

Just to be clear, is it PyCharm or Python giving you this error? (I only ask because I don't know your experience level and newbies often have a hard time distinguishing between their IDE and the programming language)

Going into python3 on terminal and typing the commands in gives no errors. pycharm gives the error, and all googling seems to indicate the error is pycharm's.

Also cannot figure out how to sudo apt-get upgrade pycharm3. Right clicking it for details from the menu says it literally cannot find pycharm-community_pycharm-community.desktop, dpkg -l |grep "pycharm" gives nothing either. (it launchs despite being some kind of phantom app)

QuarkJets
Sep 8, 2008

Does pycharm have the ability to do a project-level replacement of .format strings with f-strings? It can definitely do it on single lines but I can't seem to find the ability to do it globally and Google isn't helping.

susan b buffering
Nov 14, 2016

QuarkJets posted:

Does pycharm have the ability to do a project-level replacement of .format strings with f-strings? It can definitely do it on single lines but I can't seem to find the ability to do it globally and Google isn't helping.

I think you can use code inspections to do this. On my phone so can’t check.

Thermopyle
Jul 1, 2003

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

Hemingway To Go! posted:

Going into python3 on terminal and typing the commands in gives no errors. pycharm gives the error, and all googling seems to indicate the error is pycharm's.

Also cannot figure out how to sudo apt-get upgrade pycharm3. Right clicking it for details from the menu says it literally cannot find pycharm-community_pycharm-community.desktop, dpkg -l |grep "pycharm" gives nothing either. (it launchs despite being some kind of phantom app)

Do you have the correct interpreter selected for your project?

Hemingway To Go!
Nov 10, 2008

im stupider then dog shit, i dont give a shit, and i dont give a fuck, and i will never shut the fuck up, and i'll always Respect my enemys.
- ernest hemingway
Yeah. Says it has the libraries installed. Just has errors when I try to use them. Again using the same commands from the terminal has no problem.

Thermopyle
Jul 1, 2003

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

Hemingway To Go! posted:

Yeah. Says it has the libraries installed. Just has errors when I try to use them. Again using the same commands from the terminal has no problem.

Weird stuff. Like you said there's not much on Google about this.

Maybe try it the trial Pro version of PyCharm?

KICK BAMA KICK
Mar 2, 2009

Feel like your PyCharm installation is broken somehow, not necessarily your code or environment.

Hemingway To Go! posted:

"AttributeError: 'InputHookManager' object has no attribute '_stdin_file'"
Just a guess but that really feels like it's some code PyCharm uses in the process of building skeletons of your project and its libraries for code completion, etc. IDK if you (or something else on your system) did anything like move your PyCharm executables around, maybe unintentionally, but I would just nuke and reinstall PyCharm (making sure to save your code somewhere safe) and open your code up again as a new project, creating a new virtualenv, the whole nine yards.

e: same issue (I think) on StackOverflow: https://stackoverflow.com/questions/57260720/unable-to-execute-the-code-matplotlib-pyplot-as-plt-in-pycharm-attributeerror with a response from a dev in the comments linking to a bug report that's five years old, not fixed and I can't really tell if that's still the same problem you're having?

KICK BAMA KICK fucked around with this message at 23:18 on Dec 2, 2019

Thermopyle
Jul 1, 2003

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

Hemingway To Go!: I voted on the issue for you. Hopefully it gets some attention sooner rather than later.

Hemingway To Go!
Nov 10, 2008

im stupider then dog shit, i dont give a shit, and i dont give a fuck, and i will never shut the fuck up, and i'll always Respect my enemys.
- ernest hemingway
Just uninstalled and reinstalled pycharm and it still cannot deal with matplotlib. Will see if I cannot find a python Dev irl for help.

a foolish pianist
May 6, 2007

(bi)cyclic mutation

unpacked robinhood posted:

I'd like to do realtime reporting on thousands of network tasks being processed, possibly using websockets to push updates to a browser. They're part of a big batch i need to keep tabs on.

I'm not sure how to reason about this.

Reading about concurrent.futures made me want to use those, but I'm not sure how to tally updates on the current state of the system, considering each task can have a few states (likely common stuff like "pending", "failed" and "done")

How can a simple network task inform the rest of the system of its state in an elegant way ? Maybe have each task update its state to a redis instance, but then I'd need something to watch over Redis and push updates when they happen (avoiding polling would be nice).

This is a complicated thing, but you'll probably need to use some kind of simple redis queue system, something like this:

http://peter-hoffmann.com/2012/python-simple-queue-redis-queue.html

Have your events post their completions to a couple of different queues, and have a couple of different daemons polling these queues, grabbing events, and updating whatever it is you want to view the events with. If you've got a lot of things going on simultaneously, some kind of supervisorctl-style process manager will be really helpful.

QuarkJets
Sep 8, 2008

Hemingway To Go! posted:

Just uninstalled and reinstalled pycharm and it still cannot deal with matplotlib. Will see if I cannot find a python Dev irl for help.

Did you try creating a new environment and configuring pycharm to use it?

LuckySevens
Feb 16, 2004

fear not failure, fear only the limitations of our dreams

I'm working on a Jupyterhub app and I'm looking for the best way to convert a flowchart created in an image editing package (indifferent to which, have looked at draw.io, which works with Jupyter out of the box) into a python data structure to be passed to another app/db. Users can wire up a basic diagram which becomes some kind of output (once again, open to how to do this), and which is processed by another visualisation app. Can be a manual process, not necessarily dynamic hooks or whatever, it's just to help out the non-coders to start a new template.

Any ideas on where to start?

Edit: Graphviz https://graphviz.readthedocs.io/en/stable/ does the kind of thing I'm thinking, albeit without a GUI drawing interface.

LuckySevens fucked around with this message at 11:10 on Dec 4, 2019

CarForumPoster
Jun 26, 2013

⚡POWER⚡

LuckySevens posted:

I'm working on a Jupyterhub app and I'm looking for the best way to convert a flowchart created in an image editing package (indifferent to which, have looked at draw.io, which works with Jupyter out of the box) into a python data structure to be passed to another app/db. Users can wire up a basic diagram which becomes some kind of output (once again, open to how to do this), and which is processed by another visualisation app. Can be a manual process, not necessarily dynamic hooks or whatever, it's just to help out the non-coders to start a new template.

Any ideas on where to start?

Edit: Graphviz https://graphviz.readthedocs.io/en/stable/ does the kind of thing I'm thinking, albeit without a GUI drawing interface.

I've used (~1 year ago) graphviz to display inline decision trees generated by sklearn. I imagine a flowchart is possible as well. I recall the binary being fucky to install but not much else about it other than it got it done.

Coco13
Jun 6, 2004

My advice to you is to start drinking heavily.
I just got feedback on a homework assignment and I need to see if I'm crazy or not. The task was read a JSON list of cars into Python and create a dictionary and a list of each car in the JSON file and certain attributes like horsepower or mileage. My code's below.

The feedback was 'overcomplicated, check these commits.' The code examples he gave all explicitly wrote out each variable to some form. One was close to what I did, just wrote out the dictionary key instead of calling it as a stored variable. The other two created the list first, and then referenced the place in the list to create the dictionary.

I can see how their entries are more straightforward and just work, but if I needed to grab another variable, it'd take a minute to update everything successfully, maybe 2 if it required a different amount of nested JSON than I had built. Also, if I'm the TA looking at something like 45 different people's code for the same task I'd want them to not throw curveballs whenever possible.

\/\/\/ durf
code:
self.all_cars_list = []
        self.all_cars_by_make = {}
        carinfo = [["Identification", "Model_Year"], ["Identification", "ID"], 
                   ["Engine_Information","Engine_Statistics","Horsepower"],
                   ["Identification","Year"],  ["Fuel_Information", "Highway_mpg"], 
                   ["Fuel_Information", "City_mpg"], ["Dimensions", "Width"], ["Engine_Information", "Hybrid"]]
        with open(filename, 'r') as cars_data:
            # create Python object of JSON data called 'cars_list'
            cars_list = json.load(cars_data)
            for car in cars_list:
                cardict = {}
                carlist = []
                for info in carinfo:
                    if len(info) == 2:
                        cardict[info[1]] = car[info[0]][info[1]]
                        carlist.append(car[info[0]][info[1]])
                    else:
                        cardict[info[2]] = car[info[0]][info[1]][info[2]]
                        carlist.append(car[info[0]][info[1]][info[2]])
                self.all_cars_list += [carlist]
                if car["Identification"]["Make"] in self.all_cars_by_make:
                    self.all_cars_by_make[car["Identification"]["Make"]].append(cardict)
                else:
                    self.all_cars_by_make[car["Identification"]["Make"]] = [cardict]

Coco13 fucked around with this message at 00:41 on Dec 6, 2019

Thermopyle
Jul 1, 2003

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

Coco13 posted:

I just got feedback on a homework assignment and I need to see if I'm crazy or not. The task was read a JSON list of cars into Python and create a dictionary and a list of each car and certain attributes like horsepower or mileage. I created an array of the JSON variables: [["Engine_Information","Engine_Statistics","Horsepower"], ["Fuel_Information", "Highway_mpg"], ["Fuel_Information", "City_mpg"]]. For each JSON car entry iterated over that array to create my dictionary and list to get the information, using the last entry of the JSON as my dictionary key: cardictionary[json_variable[1]] = json_car[json_variable[0]][json_variable[1]]

The feedback was 'overcomplicated, check these commits.' The code examples he gave all explicitly wrote out each variable to some form. One was close to what I did, just wrote out the dictionary key instead of calling it as a stored variable. The other two created the list first, and then referenced the place in the list to create the dictionary.

I can see how their entries are more straightforward and just work, but if I needed to grab another variable, it'd take a minute to update everything successfully, maybe 2 if it required a different amount of nested JSON than I had built. Also, if I'm the TA looking at something like 45 different people's code for the same task I'd want them to not throw curveballs whenever possible.

I can't understand what your saying you did or what you're saying they're wanting you to do.

Provide code in code tags dude!

Dominoes
Sep 20, 2007

The way you're grouping the data is weird, but maybe that's related to the assignment requirements. It's hard to tell from your example what the input and expected output formats are. Using collection len to determine how to categorize seems fragile. I recommend avoiding using types in var names.

Dominoes
Sep 20, 2007

Also, don't put more than you need in the with open block. Here's one way to do this, where we assume the JSON is organized in a clean way. Notice how I'm defining data structures first? It makes it clear what the result should look like, and what we're accomplishing.

Python code:
class Hybrid(Enum):
    CONVENTIONAL = auto()
    ELECTRIC = auto()
    HYBRID = auto()

    @classmethod
    def from_str(cls, s: str) -> Hybrid:
        if s == "conventional":
            return cls.CONVENTIONAL
        elif s == "electric":
            return cls.ELECTRIC
        elif s == "hybrid":
            return cls.HYBRID
        else:
            raise AttributeError("Bad hybrid data")


@dataclass
class FuelInfo:
    city_mpg: float
    highway_mpg: float


@dataclass
class Car:
    identification: str
    id: int
    model_year: int
    fuel_information: FuelInfo
    # You could also use a dataclass for dimensions, for type safety, ie so 
    # you can't mix it up with other 3-tuples.
    dimensions: Tuple[float, float, float]
    hybrid: Hybrid
    # etc


def parse(filename: str) -> List[Car]:
    result = []

    with open(filename, 'r') as cars_data:
        cars_parsed = json.load(cars_data)

    for car in cars_parsed:
        result.append(Car(
            car['identification'],
            car['id'],
            car['model_year'],
            FuelInfo(car['fuel_information']['city_mpg'], car['fuel_information']['highway_mpg']),
            # (some parsing code for the string to a tuple)
            Hybrid.from_str(car['hybrid'])
            # etc
        ))
    
    return result
Or, if the JSON data matches the data structure reasonably well, you could cheat and use something like pydantic to auto convert the JSON to your data structure. That's what I'd do real-world for a [de]serialization task like this. It would auto-convert JSON to Python types as appropriate, and let you inject custom parsers when required. (Maybe even auto-use a from_str method, but I'm not sure) Ie you'd just write result.append(Car(**car)) instead of that last part.

Tangent: Do I need @classmethod in the above code near the top? What does it do besides provide the cls argument, which could just be the class's name.

Dominoes fucked around with this message at 02:08 on Dec 6, 2019

breaks
May 12, 2001

classmethod makes it still work as expected if subclassed and those attributes are overridden but the method isn’t.

Just one of those low cost abstraction things that helps prevent you from loving up things you didn’t anticipate or were like, there’s never going to be a reason someone would do that, which of course inevitably happens, imo.

I wasn't thinking about the fact that it was an Enum. I think in this case it doesn't make any actual difference, but I'd still use a classmethod anywhere I'm using only the class as some kind of ironclad law that I can't think of a sane counterexample for at the moment and I'm sure someone will provide.

breaks fucked around with this message at 02:21 on Dec 6, 2019

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 just discovered numpy.piecewise and I'm having a hard time understanding why it exists or why I should use it.

code:
def foo(x):
    if x < 0:
        return abs(x)
    elif x < 10:
        return (x + 1) / 2
    return x ** 2
code:
def bar(x):
    return np.piecewise(
        x,
        [x < 0, 0 <= x < 10, x >= 10],
        [lambda y: abs(y), lambda y: (y + 1) / 2, lambda y: y ** 2]
    )
Why would I ever want to use the second one over the first one? It's less readable, and I would imagine there is a non-zero cost to define those lambda functions over and over again if this was something that gets called a lot. Not to say that the cost would be impactful, but just that it's not "free" like the first function right?

Boris Galerkin fucked around with this message at 13:39 on Dec 6, 2019

QuarkJets
Sep 8, 2008

Boris Galerkin posted:

I just discovered numpy.piecewise and I'm having a hard time understanding why it exists or why I should use it.

code:
def foo(x):
    if x < 0:
        return abs(x)
    elif x < 10:
        return (x + 1) / 2
    return x ** 2
code:
def bar(x):
    return np.piecewise(
        x,
        [x < 0, 0 <= x < 10, x > 10],
        [lambda y: abs(y), lambda y: (y + 1) / 2, lambda y: y ** 2]
    )
Why would I ever want to use the second one over the first one? It's less readable, and I would imagine there is a non-zero cost to define those lambda functions over and over again if this was something that gets called a lot. Not to say that the cost would be impactful, but just that it's not "free" like the first function right?

The first one doesn't work if x is an array, but the second one does (or would, with a few modifications)

The lambdas aren't redefined multiple times, they're just defined once and passed to piecewise as function objects. The difference is that applying foo to every element of an array would require multiple calls to foo, whereas piecewise is defined to operate on the entire array, not just one element.

QuarkJets fucked around with this message at 10:51 on Dec 6, 2019

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!
What is the proper way to make it work with arrays anyway? I always get that "truth value of an array… use a.any() or a.all()" error and I never know how to deal with that and the message just isn't helpful. Passing np.arange(-10, 11, 1) to both functions as written raises the same error.

QuarkJets
Sep 8, 2008

Boris Galerkin posted:

What is the proper way to make it work with arrays anyway? I always get that "truth value of an array… use a.any() or a.all()" error and I never know how to deal with that and the message just isn't helpful. Passing np.arange(-10, 11, 1) to both functions as written raises the same error.

Python code:
def bar(x):
    return np.piecewise(
        x,
        [x < 0, (x >= 0) & (x < 10), x >= 10],
        [lambda y: abs(y), lambda y: (y + 1) / 2, lambda y: y ** 2]
    )
You can't do basic chained comparisons with arrays, but you can combine comparisons with logical operators

LuckySevens
Feb 16, 2004

fear not failure, fear only the limitations of our dreams

CarForumPoster posted:

I've used (~1 year ago) graphviz to display inline decision trees generated by sklearn. I imagine a flowchart is possible as well. I recall the binary being fucky to install but not much else about it other than it got it done.

Worth a look ay, thanks!

Coco13
Jun 6, 2004

My advice to you is to start drinking heavily.

Dominoes posted:

The way you're grouping the data is weird, but maybe that's related to the assignment requirements. It's hard to tell from your example what the input and expected output formats are. Using collection len to determine how to categorize seems fragile. I recommend avoiding using types in var names.

A: Thanks!
B: The if/then for the elements of carinfo is the part I wish I could change the most, but didn't have an inkling on how.
C: The grouping is because of the requirements. They are:

quote:

Step 1 - Initialize the following 2 instance variables:
self.all_cars_by_make - make this a dictionary.
self.all_cars_list - make this a list.
Step 2 - Populate both containers (from step 1) with values for the following fields: Model_year Model_id year horsepower highway_mpg city_mpg width hybrid
(example shows in that order as well.)

Which, thinking about it a little more, is really odd because the lesson was on making classes in Python. So, the examples were a robot class, and building individual robots, and the homework was to take all these cars and make one object that had all these cars as a list and dictionary instance variables.

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!

QuarkJets posted:

Python code:
def bar(x):
    return np.piecewise(
        x,
        [x < 0, (x >= 0) & (x < 10), x >= 10],
        [lambda y: abs(y), lambda y: (y + 1) / 2, lambda y: y ** 2]
    )
You can't do basic chained comparisons with arrays, but you can combine comparisons with logical operators

Got it, thanks. Also thanks for fixing the third condition for me :eng99:.

Would it make any sense/difference to define those three lambdas as functions?

Python code:
def bar1(x): return abs(x)

def bar2(x): return (x + 1) / 2

def bar3(x): return x ** 2

def bar(x):
    return np.piecewise(
        x,
        [x < 0, (x >= 0) & (x < 10), x >= 10],
        [bar1, bar2, bar3]
    )
One reason is that these functions in a real use case aren’t so simple as these examples, and another is that this is better testable and easier to read/understand.

Dominoes
Sep 20, 2007

breaks posted:

classmethod makes it still work as expected if subclassed and those attributes are overridden but the method isn’t.

Just one of those low cost abstraction things that helps prevent you from loving up things you didn’t anticipate or were like, there’s never going to be a reason someone would do that, which of course inevitably happens, imo.

I wasn't thinking about the fact that it was an Enum. I think in this case it doesn't make any actual difference, but I'd still use a classmethod anywhere I'm using only the class as some kind of ironclad law that I can't think of a sane counterexample for at the moment and I'm sure someone will provide.
I appreciate the details. That clears things up entirely - It sounds like using classmethod is the more general and idiomatic approach.

Dominoes
Sep 20, 2007

Next tangent: Is there a standard/idiomatic way to do do the from_str method/constructor I posted? Ie, an analog of __str__, but does the inverse. Is there a different way you would have written that method?

Dominoes fucked around with this message at 05:55 on Dec 8, 2019

Thermopyle
Jul 1, 2003

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

__repr__ is supposed to be that...aka the output of repr is supposed to be what you need to construct the object if at all possible.

QuarkJets
Sep 8, 2008

Boris Galerkin posted:

Got it, thanks. Also thanks for fixing the third condition for me :eng99:.

Would it make any sense/difference to define those three lambdas as functions?

Python code:
def bar1(x): return abs(x)

def bar2(x): return (x + 1) / 2

def bar3(x): return x ** 2

def bar(x):
    return np.piecewise(
        x,
        [x < 0, (x >= 0) & (x < 10), x >= 10],
        [bar1, bar2, bar3]
    )
One reason is that these functions in a real use case aren’t so simple as these examples, and another is that this is better testable and easier to read/understand.

Totally! I actually never use lambdas in my own code, personal preference

amethystdragon
Sep 14, 2019

CarForumPoster posted:

I've used (~1 year ago) graphviz to display inline decision trees generated by sklearn. I imagine a flowchart is possible as well. I recall the binary being fucky to install but not much else about it other than it got it done.

Love using graphviz. No drag and drop GUI, but its built as code (like an SVG) so it can be checked in and versioned.

Meant to look into getting it incorporated to doc strings, but haven't gotten that far yet. Ideally you could put in a module or class level flow diagram for more complicated business logic and have it built and added to any output documentation as an image.

Beef
Jul 26, 2004

amethystdragon posted:

Love using graphviz. No drag and drop GUI, but its built as code (like an SVG) so it can be checked in and versioned.

Meant to look into getting it incorporated to doc strings, but haven't gotten that far yet. Ideally you could put in a module or class level flow diagram for more complicated business logic and have it built and added to any output documentation as an image.

I have some experience in doing what you described. I made a dot file 'subway map' that walks through the parts of the code being touch during a typical execution scenario. The generated SVG figures are imported by the markdown documentation files. Everything is just text checked into the repo, with figures generated at build time by the makefiles.

Some cool features:
- URL link attributes on nodes/edges: you can click on nodes in the generated SVG figure to jump to the Doxygen documentation of said class or method. As long as the name doesn't change, it will not break the link.
- Viewports: you can zoom into specific rectangles of your figure, e.g. to zoom into the context around the specific method you are describing in the documentation. I rigged up a script to take a list of nodes, fetch their coordinates and generate a viewport enveloping those coordinates.

IIRC you can use dot files with Doxygen, but I have not tried putting it in docstrings.

unpacked robinhood
Feb 18, 2013

by Fluffdaddy
If Thread subclasses A, B and C hold a reference to a shared object, things are fine if only thread A ever writes to the object, while others only read from it, right ?

amethystdragon
Sep 14, 2019

unpacked robinhood posted:

If Thread subclasses A, B and C hold a reference to a shared object, things are fine if only thread A ever writes to the object, while others only read from it, right ?

quote:

things are fine

Depends on what you mean by "fine"

bigperm
Jul 10, 2001
some obscure reference
I've been trying to teach myself python and I've been going through the assignments at [practice python]. This is problem 4 (return factors of given number) and I see that there are one line list comprehension solutions and even better ways of doing it in a for loop but after trying and failing I don't see how just copying the solution and saving it in a file on my laptop would really teach me anything.

I just can't figure out why my code here doesn't work. It only outputs a list containing the original number.If anyone could tell me what is wrong here I would really appreciate it.

At first I had my poo poo set up wrong and it was running it in 2.7 but once I fixed that it seems that this works the same (ie, it doesn't) in 3.6.

code:
numb = int(input('Number ? '))

range_list = list(range(1, numb + 1))

div_list =[]

for n in range_list:
    if n % numb == 0:
        div_list.append(n)
      
print(div_list)

Adbot
ADBOT LOVES YOU

QuarkJets
Sep 8, 2008

bigperm posted:

I've been trying to teach myself python and I've been going through the assignments at [practice python]. This is problem 4 (return factors of given number) and I see that there are one line list comprehension solutions and even better ways of doing it in a for loop but after trying and failing I don't see how just copying the solution and saving it in a file on my laptop would really teach me anything.

I just can't figure out why my code here doesn't work. It only outputs a list containing the original number.If anyone could tell me what is wrong here I would really appreciate it.

At first I had my poo poo set up wrong and it was running it in 2.7 but once I fixed that it seems that this works the same (ie, it doesn't) in 3.6.

code:
numb = int(input('Number ? '))

range_list = list(range(1, numb + 1))

div_list =[]

for n in range_list:
    if n % numb == 0:
        div_list.append(n)
      
print(div_list)

You've got your operation reversed, you should be checking numb % n == 0 (e.g 10 % 2 == 0 but 2 % 10 does not)

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