@PawelFlajszer do you like to break stuff? You'll be trying to do that a lot as a tester
Some people really enjoy it
It's a bit like lightweight hacking, sometimes
@AlexanderReynolds You mean, writing a package so you can pip install it? github.com/waynew/simplest-python-package is a really simple example I wrote that you may find useful
@WayneWerner I'm aware of that but I'm wondering if there is a way (within Python itself) to be able to run this program without the user activating the virtual environment.
I guess that's what pyinstaller does
didn't really realize that my question was "how do I make my CLI an executable" but I guess it is, which makes the answers obvious. But, thanks for the suggestion, that's a handy thing to have around to point people to anyways
@AlexanderReynolds btw, found out how to do this with asyncio.wait_for with a timeout---the async method just processes the data so the timeout just stops it running.
@AlexanderReynolds You could create a virtualenv for the user and then install your package in it. All they need is ~/.local/bin, or equivalent on their path
Yeah, that doesn't work like I'm asking---you have to activate the .virtualenvs/pymato venv to have pymato on your PATH
I want someone to be able to do something like pip install <some github repo>/mytool and then just go mytool option1 option2 and be done with it. Which just means to create an executable, I guess. I mean, I know how to do it now that I've phrased it right (at least, with other tools, dunno how to do this myself)
If you create a package (source, or preferably wheel), like my sample app, and upload it to pypi you can have them simply do python -m pip install --user <yourpackage>
that's only a problem if you have pinned dependencies that conflict with others they have installed.
Though if you really wanted to ensure isolation you could create an installer packages with no deps that creates the virtualenv and installs your "real" app there
Or maybe just vendor everything into a zip? I have some kind of recollection that that might be a thing someone can do, if they were so inclined ;)
Yeah I mean I think the simplest thing to do what I want is...just make it so that when it's installed it gets a venv created in its directory and the shebang for the python file just points there
In business, overhead or overhead expense refers to an ongoing expense of operating a business. Overheads are the expenditure which cannot be conveniently traced to or identified with any particular cost unit, unlike operating expenses such as raw material and labor. Therefore, overheads cannot be immediately associated with the products or services being offered, thus do not directly generate profits. However, overheads are still vital to business operations as they provide critical support for the business to carry out profit making activities. For example, overhead costs such as the rent for...
I'm not a fan of the word in listOfWords[0] thing, because if the OP really has a list with only 1 element, there's something fundamentally wrong... pretty sure they actually need any(...) there
hello
x = [url1,url2,url3,url4,....url50]
t2 = datetime.time(datetime.now())
print("before : ",t2)
for key in x:
y = test1.query.filter(test1.url == key).all()
if y:
print('----i got it')
else:
print('no')
t3 = datetime.time(datetime.now())
print("after forloop : ",t3)
>>>> this process take 5 Seconds on LOCALHOST with 1 client where my Database have 1 entire only ( postgreSQL )
x = [url1,url2,url3,url4,....url50]
t2 = datetime.time(datetime.now())
print("before : ",t2)
for key in x:
y = test1.query.filter(test1.url == key).all()
if y:
print('----i got it')
else:
print('no')
t3 = datetime.time(datetime.now())
print("after forloop : ",t3)
>>>> this process take 5 Seconds on LOCALHOST with 1 client where my Database have 1 entire only ( postgreSQL )
sorry couldnt edit the first one and i cant delete it now
but the part which is taking time is test1.query.filter() which we can only speculate about ... how are you connecting, are you using an ORM, how is the database configured?
@za001a I'm no DBA but for anyone to say anything meaningful about this, we would need to know more details. For example, are you connecting to a database on localhost with low latency, or is the one-second turnaround an amazing performance against a remote database in Australia with poor connectivity?
(replace Australia with Svalbard if you are in Australia)
@AndrasDeak so you are suggesting that the python code itself is not usually that slow " i shouldn't worry about it and it will be fixed right after i setup up my system on USA/UK server ?
@za001a yes, the only thing which can be optimized is the query which we don't have the code for still, nor do we still know how you are connecting to the database or what sort of latency to expect
I would say go run it in production and see if it's still too slow; then maybe think about how to optimize; but then it's probably more of a Postgres topic than a Python topic (and like I said, I'm no Postgres expert)
unless you can demonstrate that SQL Alchemy has bugs and creates suboptimal queries
Haha, my wife went to school in College Station so she has tons of friends she wants to see and is actually encouraging me to go. The other bonus is that I'm in my last semester of grad school so I could still get a student discount.
@Dodge Sounds like a plan to me. I literally know noone IRL in this hemisphere who knows Python/codes professionally, so I'm hoping to meet some folks :)
@ParitoshSingh It is, but it can be any letter and any number. If possible also lowercase letters followed by uppercase letters. I know how to do it for specific letters and numbers but not for unspecified ones
I've instantiated an object in my script a = SomeObject() .. Inside PDB, is it possible to run something like a.someObjectMethod() exclusively in the command line and step into that function with the debugger at the same time?
Something like this works for example. @mtbrands but you may want to refine it based on your needs
import re
test = "abcABC123"
result = re.findall(r"[a-z]+|[A-Z]+|\d+", test)
print(result)
#['abc', 'ABC', '123']
@toonarmycaptain The method call isnt actually inside the script, I just wanted to step through it in a virtual debugging envrionment, its straight forward enough in PyCharm... but I'm trying to use the CLI
@Sam I read somewhere that hitting breakpoint() will drop you into pdb? So if you put it in the method definition, and you trigger the method call in the console/CLI, it might work how you want?
Interesting, type(mod.myclass) != type(app.mod.myclass) even though they are the same class just imported via from app.mod import myclass and from mod import myclass.
My issue was that I have a class Class with add_student method that can either take a Student object or instantiate one from parameters. And it wasn't adding to the class.
>>> from dionysus_app.class_ import Class
>>> d = Class('d')
>>> d.add_student(plain_student)
>>> d.students
[]
>>> d.add_student(plain_student)
>>> d.students
[]
>>> d.add_student(full_student)
>>> d.students
[dionysus_app.student.Student(name='full import', avatar_path=None)]
url = []
for i in range(0,1):
url.append(f'https://www.filmweb.pl/user/pflajszer/films?page={i+1}')
req = requests.get(url[i])
soup = BeautifulSoup(req.content, 'lxml').prettify()```
Hmm I guess this is part of Pycharm's I-know-about-your-project magic, because from the same cwd in cmd I do get a ModuleNotFoundError when I try to plain from student import Student
If I have a CLI and need to take an arbitrary number of pairs as input...e.g., (ipaddress, filename) pairs...what do y'all find more common/natural: script.py ip1 fn1 ip2 fn2 ... or script.py ip1 ip2 ... fn1 fn2 ... ?
Your data consists of (ip, fn) pairs, so read it that way. Having 2 separate lists that have to be synchronised exactly is just asking for something to go wrong.
my point is if you think you can distinguish filenames and ip addresses, you shouldn't, so try to think of an interface where you don't need to do that at all
Short question. I have a file containing a couple of classes. I import it via from folder.file import classes. Now I'd like to asign one of the classes based on previous inputs. Currently I'm using globals()[input] but it feels somewhat clunky. I probably should redesign but still wanted to figure a neat way to implement it that way. Any suggestions to do it less "clunky"? or is that pretty much it.
@ParitoshSingh not that memory is a big concern but wouldn't that basically mean I have the same object loaded twice? But yeah that would probably the easiest solution. While designing I had something reflection like in mind but I feel like that's not really a thing in python?
I think we need more context here... I'm not sure what that dict has to do with your imports. Are you planning to store imported modules/classes/functions in that dict?
Well I'm more experienced in C# and reflections is a rather common solution there so I thought to access the object based on the input via reflection. @Aran-Fey I was trying to get rid of a `globals()[index] do access a class I used within an import. meaning I don't know which class exactly I need until it's being input by a user.
In that case I'd say using globals()[index] is... fine, as long as you're sure the user can't gain access to something they're not supposed to have access to. Like, if the user somehow manages to instantiate an AngryDinosaur instead of a FluffyTeddybear, you might have a problem
I've all classes imported in the beginning, during the user is able to configure his own instance and depending on his configs I need to access a different class @ParitoshSingh
Well it's basically a discord bot, user's are able to set up specifics in an config, stored in an MySQL DB. Depending on the settings stored there I need to access a specific class. It's not well designed. That project is from the beginning of my python experience. Many .NET influences there :/
@wim don't quite get it, can you explain what you mean?
ah. Well, frankly either ways that sounds good, its great to build something and get it up and running. As you go along, im sure you can probably refactor things that you end up disliking.
I have many applications where I need to select a class from among many candidates. Usually I create a registry of some sort so that I can find the class by some sort of tag, or by iterating over a list of candidate classes and testing each for a match based on some context criteria against class-level match values in each candidate class.
Having the user specify an actual class name feels weird on several levels.
Hi all. Yesterday I posted a question, and I was able to come up with a solution. Is it possible for you guys to have a look at it and give some feedback? Any feedback is welcome. As a beginner I'm looking to learn as much as possible.
Well I define the names, he just has to select the one that fits. The idea was to implement it like an interface to enforce specific properties that have to be available. Then have classes implement that interface and from there be able to provide a selection. Didn't quite get the interface part to work though. But the idea has been to write the method just once and get the results I need.
But yeah I guess having a dict with the classes would be the "most elegant" solution for this. Or refactor :)
@scientific_explorer We generally avoid very recent questions in chat here. sopython.com/chatroom <- rules. Having said that, that question doesnt really fit SO, but perhaps you may want to try codereview.stackexchange.com sister site if you have working code.
@PaulMcG that's an interesting solution. Well as said, I define the list of names, they just get to choose one so no headache for me on the user define class names part.
They have to "write" it in the discord chat but only the ones I defined are accepted and replaced with the string I defined in code, that should avoid all sneaky ways.
TIL raise <new exception>('new error message') from <old exception>
>>> try:
... [][0]
... except IndexError as e:
... raise IndexError('new error message') from e
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
IndexError: list index out of range
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
IndexError: new error message
The perfect question for me.
You can suppress the exception context, that is the first part of the traceback, by explicitly raising the exception from None:
>>> try:
raise KeyboardInterrupt
except:
raise Exception from None
Traceback (most recent call last):
File "<pyshell#4
I would have preferred the feature was added in such a way that libraries which support 2.7 as well could have actually used it too
instead, you have 2 choices, both bad: 1) use the exception chaining in your_mod3.py and duplicate your code in your_mod2.py, conditionally importing one module or the other. 2) generate the code string and exec it.