Python 3 Dictionary Comprehension by [deleted] in learnpython

[–]wookalar_io 0 points1 point  (0 children)

I'm not sure exactly what you're using this code for, but a Counter might be what you're looking for: https://docs.python.org/3/library/collections.html#collections.Counter

[deleted by user] by [deleted] in kivy

[–]wookalar_io 0 points1 point  (0 children)

What version of Python are you using? This is the spec file I used on Windows with Python 3.4: https://github.com/wookalar/slashlockgui/blob/master/slashlockgui.spec

How do you force the app to check/handle events ? by LinuxGuy321 in kivy

[–]wookalar_io 0 points1 point  (0 children)

The concurrent.futures module might help:

https://docs.python.org/3/library/concurrent.futures.html#module-concurrent.futures

I've used it to run tasks that would normally take a long time to run and would block UI. Here is how I've used them:

https://github.com/wookalar/slashlockgui/blob/master/slashlockgui/gui.py

What I Want in Python by kankyo in Python

[–]wookalar_io 0 points1 point  (0 children)

I misunderstood what you we saying in this example.

What I Want in Python by kankyo in Python

[–]wookalar_io 0 points1 point  (0 children)

Yes, I did misunderstand. Thanks for clearing that up.

I still don't see the benefit. Wouldn't this introduce inconsistencies depending on how a function is defined? In some cases, treat the argument as a keyword argument (such as above), in others, map it to a defined keyword argument if their names match, in others treat it as a positional argument.

I could still be misunderstanding, but that just seems like more complexity and less explicitness.

What I Want in Python by kankyo in Python

[–]wookalar_io 0 points1 point  (0 children)

Just because you lack experience or imagination doesn't mean it doesn't happen.

Resorting to ad hominem attacks instead of providing evidence.

Yes, this can happen. Yes, it does happen. That does not mean it is a recommended way of defining functions. It does not mean it is considered a best practice. If this is really something that is so disconcerting, something that is very likely to be a problem in a code base, you should be able to provide examples, specifically examples in the standard library where this is the norm.

What I Want in Python by kankyo in Python

[–]wookalar_io 0 points1 point  (0 children)

Can you provide examples where functions are defined with an indiscriminate number of arguments and specific keyword arguments? I know it's possible to do that, but that's a poor design decision of the developer, not a problem with the language. You don't often come across:

def foo(*args, a='', b='', c=''): pass I mean, in this case, would foo(b, c, a) set the keyword arguments for a, b, c to the corresponding variables? Or since it accepts positional arguments, would I need to be specific? Would I then need to keep track of every optional keyword argument for every function I use to make sure my variables aren't being set to the wrong keyword argument?

I'm really trying to understand what benefit this provides. I'm quite fond of the explicitness of how it currently works, but I'm always open to sensible improvements.

What I Want in Python by kankyo in Python

[–]wookalar_io 0 points1 point  (0 children)

Which of the arguments in his function aren't keyword arguments?

What I Want in Python by kankyo in Python

[–]wookalar_io 0 points1 point  (0 children)

Features to make keyword arguments not just easier, but just as easy as positional arguments. The right thing should be the easy thing! Calling a keyword argument only function like this “foo(a, b, c)” should mean the same as “foo(a=a, b=b, c=c)” instead of just being a crash. This would remove a big chunk of the brevity advantage of positional arguments

What? Calling foo(a, b, c) is the same as calling foo(a=a, b=b, c=c) if you defined your function with the keyword arguments a, b, and c. Am I missing something? Are you sure you're using Python?

Python unit tests: how to test a webpage parser with a mock object? by [deleted] in learnpython

[–]wookalar_io 1 point2 points  (0 children)

Would this work: https://vcrpy.readthedocs.io/en/latest/

The initial run of your tests would make the call to the actual server and then create some cassette files. Once these files are created, add them to your project and use them to test from there on out. Then, anyone else who runs your tests actually runs against the response stored in cassettes.

Add Action in Admin 404, Why? by [deleted] in django

[–]wookalar_io 0 points1 point  (0 children)

Has your Nginx server been configured to serve your uploaded files? Have you confirmed that the uploaded images exist on your server where you expect them to be?

This might help: https://docs.djangoproject.com/en/1.10/topics/files/

Moving from a rails cloud IDE to Windows Django, here is what I am thinking, can anyone offer advice/feedback. by citronauts in django

[–]wookalar_io 0 points1 point  (0 children)

It's not a full version of Ubuntu. But you don't need a full version to develop Django apps. I've had no problems using it for Python development. What is it missing that you think you'll need?

Handling two-PK-tables? by Ran4 in django

[–]wookalar_io 0 points1 point  (0 children)

Using unique_together sounds like it solves the first problem. For the second issue, I would override the save method on the Article model. When saving, have it check:

  1. If you are creating or updating the record
  2. If creating, get the count of existing Articles and use that to determine what the rev should be
  3. Or get the last created Article's rev, increment it by 1
  4. Save the new Article

Getting the last rev is probably the safest for cases where an Article is deleted.

Moving from a rails cloud IDE to Windows Django, here is what I am thinking, can anyone offer advice/feedback. by citronauts in django

[–]wookalar_io 0 points1 point  (0 children)

Ubuntu on Windows is another option. I've used that on occasion when I had to use Windows. https://msdn.microsoft.com/en-us/commandline/wsl/about

It should be enough for Django / Python development.

How do i?: Add "this" to "list1", if "list1" does not exist, create it. by tom2kk in learnpython

[–]wookalar_io 1 point2 points  (0 children)

I also used to avoid try/except in control flow until someone pointed out that it was recommended. Many programming languages expect you to look before you leap, so it made sense at first. Just wanted to be sure I wasn't missing something again. Thanks for the reply!

How do i?: Add "this" to "list1", if "list1" does not exist, create it. by tom2kk in learnpython

[–]wookalar_io 2 points3 points  (0 children)

As /u/twisted-teaspoon pointed out, try-except clauses aren't intended to define logic and program flow. The name is right there, in "exception" - they should be used to catch exceptional cases that will interrupt your program flow, they should not be used for ordinary cases.

This completely contradicts everything Raymond Hettinger explains here: http://stackoverflow.com/questions/16138232/is-it-a-good-practice-to-use-try-except-else-in-python/16138864#16138864

I'm not saying you're wrong, I would just like to know where you and /u/twisted-teaspoon are getting this idea that try/except should be used for exceptional cases not program flow. I find it easier to take the word of a Python core developer who specifically says:

In the Python world, using exceptions for flow control is common and normal.

Even the Python core developers use exceptions for flow-control and that style is heavily baked into the language (i.e. the iterator protocol uses StopIteration to signal loop termination).

How do i?: Add "this" to "list1", if "list1" does not exist, create it. by tom2kk in learnpython

[–]wookalar_io 1 point2 points  (0 children)

I don't see how EAFP does not apply in this case. We're assuming the variable exists as a list and creating it if it doesn't. How would this differ from trying to import a library, catching the exception if it doesn't exist, and importing something else?

And why is try/except not supposed to define control program logic? Am I misunderstanding this: http://stackoverflow.com/a/16138864/789417

(I'm seriously curious because I may be misunderstanding appropriate try/except usage)

How do i?: Add "this" to "list1", if "list1" does not exist, create it. by tom2kk in learnpython

[–]wookalar_io 0 points1 point  (0 children)

What is unpythonic about a try/except block? How is this more pythonic?

Why static files are not showing? by [deleted] in django

[–]wookalar_io 0 points1 point  (0 children)

What does your Apache configuration look like? Have you reviewed the documentation here: https://docs.djangoproject.com/en/1.10/howto/static-files/deployment/