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
Nimrod
Sep 20, 2003
Which of the recommended IDE's tend to use the fewest resources? I'm on a 6 or 7 year old laptop with a whopping gig of ram and 1.6 GHz CPU, which really puts eclipse right out of the picture. I currently use VIM/ST2, but would love to try something new.

Adbot
ADBOT LOVES YOU

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
So a side-project at work may end up being deployed into a production environment in a hospital and I'm a little worried as I've never deployed anything in my life before. I've read around a bit and figured throwing together some unit tests, a binary and setting up a Windows service installer if I end up deploying to a win machine.

A few questions though:

Binary distribution:
- py2exe used to be the goto, now it looks like PyInstaller is the new thing. An .MSI installer would be up to me still though.
- Is there any benefit to deploying with ActivePython rather than CPython?

Licensing:
- Twisted - MIT, all good
- PIL - Permissive software license - Could be an issue as we wouldn't be selling the software directly but included as part of a bundled tender. Switching to something like pymaging seems like a decent alternative if that's the case.

Dominoes
Sep 20, 2007

ahmeni posted:

So a side-project at work may end up being deployed into a production environment in a hospital and I'm a little worried as I've never deployed anything in my life before. I've read around a bit and figured throwing together some unit tests, a binary and setting up a Windows service installer if I end up deploying to a win machine.

A few questions though:

Binary distribution:
- py2exe used to be the goto, now it looks like PyInstaller is the new thing. An .MSI installer would be up to me still though.
- Is there any benefit to deploying with ActivePython rather than CPython?

Licensing:
- Twisted - MIT, all good
- PIL - Permissive software license - Could be an issue as we wouldn't be selling the software directly but included as part of a bundled tender. Switching to something like pymaging seems like a decent alternative if that's the case.
AFAIK, cx_freeze is the only current way to make binaries. Py2exe and PyInstaller are legacy.

QuarkJets
Sep 8, 2008

Dominoes posted:

AFAIK, cx_freeze is the only current way to make binaries. Py2exe and PyInstaller are legacy.

When you say legacy, do you just mean 2.X? It seems to be receiving active updates

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
(Sorry for being a bit late with this reply; I'm at a conference right now and the internet is p. bad)

The March Hare posted:

On ctrl+c I want it to take the data currently in the clip board and blip it on over to the django app, and then on a separate keypress (not actually ctrl+v) I would like it to pull down the most recent entry under a certain user from the django app and store that information to the clipboard.

No, you don't want to do this on Ctrl+C. What you want is to hook into the native X11 system of "when the clipboard changes".

This is actually a bit complicated. Let me explain very basically how this works on X11. X11 was designed during the 80s when a megabyte of RAM cost a thousand dollars. Thus, when you press Ctrl+C in an application, the selected data actually isn't copied anywhere. Instead, the app says "I have the clipboard now". When you press Ctrl+V, the app you pressed Ctrl+V in contacts the app that has the clipboard and says "what's the clipboard contents? Please tell me."

That sounds all nice and neat and conveniently sidesteps storing the memory anywhere, but there's one problem: I copy some text, close the app, and try to paste. There's no app to talk to to get the data!

So, we invented this special app called a "clipboard manager". If an app has the clipboard, when it exits, it tells the clipboard manager to please take its clipboard data and store it, and thus it's around after the application is gone.

The technical documentation for this can be found in the Xlib manual and ICCCM.

Now, if you read all of that (you didn't, but play along), you might notice that there's no native X11 system of "when the clipboard changes". The flow is Set/Get on Ctrl+C/Ctrl+V, along with this magical clipboard manager that happens on app exit so we don't lose data. But fear not; although it is undocumented in those manuals, we added this as part of the amazing XFixes extension with selection events. I don't know how it works in Python, but in C, you call XFixesSelectSelectionInput to retrieve events for the SetSelectionOwner event, then respond to that event like any other event

The March Hare posted:

I had found some code that used xlib that seems like it might work, but if you are saying that it can't hook globally then I guess I should ask for an opinion on a solution that will work.

You can implement global keybindings, but I wanted to make sure you knew what you were doing. Hooking into Ctrl+C isn't the correct way to do it (you could use Edit->Copy or a right-click menu or something else like that), and it's difficult if you want to do something when the key is pressed, and also deliver it to the window normally. You would do this with XGrabKey on the root window, then listen for KeyPress/KeyRelease events. To also send it to the application as a pass-through, you need to use GrabSync, then from within the handler use XAllowEvents with ReplayKeyboard. When you retrieve this, you want to take the clipboard for yourself, so you want to XSetSelectionOwner and then respond to the SelectionNotify/SelectionRequest events like a normal conforming client. I'm not exactly sure how the Python Xlib bindings work, though; I'm used to the C API.

Oh, and if you have any questions, feel free to ask, as it's probably going to look like a monumental task at first, and the ICCCM and Xlib manuals aren't the easiest reading material if you don't understand the core concepts. Even if it seems like the dumbest question in the world, I've asked much dumber to understand this stuff.

As some advice on how to start, I'd make a simple app that uses the low-level Xlib to implement a simple thing that copies/pastes correctly with gedit. That should get you familiar enough with how X selections and events work, enough to go from there to implementing the XFixes events so you know when another app copies something to the clipboard, and then from there to "pasting" into the web service whenever the selection changes, and from there implementing the key press to "copy" it back into the local machine.

It seems like a cool project, so I'd be interesting in hearing your progress, too!

Dominoes
Sep 20, 2007

QuarkJets posted:

When you say legacy, do you just mean 2.X? It seems to be receiving active updates
Yes.

MeruFM
Jul 27, 2010
Thanks to the person who mentioned Chaco. It works well and produces nice and fast graphs. There's just one problem.

Does anyone have experience building an exe with Chaco?
Before switching from matplotlib to Chaco, I could build with PyInstaller.

Cannot do the same with Chaco.
I've tried bbfreeze, cz_freeze, pyInstaller and pyInstaller dev build.
They all either have issues with DLLs or when trying to run the executable get an "ImportError: No module named init" or a variation of it.

Here's an example that runs with the Anaconda distribution + wx installed. But none of the exe compilers work.
code:
import wx
from scipy import arange
from scipy.special import jn
from chaco.api import HPlotContainer, create_line_plot
from enable.api import Window

class PlotFrame(wx.Frame):
    def __init__(self, *args, **kw):
        kw["size"] = (850, 550)
        wx.Frame.__init__( *(self,) + args, **kw )
        self.plot_window = Window(self, component=self._create_plot())
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(self.plot_window.control, 1, wx.EXPAND)
        self.SetSizer(sizer)
        self.SetAutoLayout(True)
        self.Show(True)
        return

    def _create_plot(self):
        x = arange(-5.0, 15.0, 20.0/100)
        y = jn(0, x)
        plot = create_line_plot((x,y), bgcolor="white",
                                    add_grid=True, add_axis=True)
        container = HPlotContainer(spacing=20, padding=50, bgcolor="lightgray")
        container.add(plot)
        return container

if __name__ == "__main__":
    app = wx.PySimpleApp()
    frame = PlotFrame(None)
    app.MainLoop()

The March Hare
Oct 15, 2006

Je rêve d'un
Wayne's World 3
Buglord

Suspicious Dish posted:

(Sorry for being a bit late with this reply; I'm at a conference right now and the internet is p. bad)


No, you don't want to do this on Ctrl+C. What you want is to hook into the native X11 system of "when the clipboard changes".

This is actually a bit complicated. Let me explain very basically how this works on X11. X11 was designed during the 80s when a megabyte of RAM cost a thousand dollars. Thus, when you press Ctrl+C in an application, the selected data actually isn't copied anywhere. Instead, the app says "I have the clipboard now". When you press Ctrl+V, the app you pressed Ctrl+V in contacts the app that has the clipboard and says "what's the clipboard contents? Please tell me."

That sounds all nice and neat and conveniently sidesteps storing the memory anywhere, but there's one problem: I copy some text, close the app, and try to paste. There's no app to talk to to get the data!

So, we invented this special app called a "clipboard manager". If an app has the clipboard, when it exits, it tells the clipboard manager to please take its clipboard data and store it, and thus it's around after the application is gone.

The technical documentation for this can be found in the Xlib manual and ICCCM.

Now, if you read all of that (you didn't, but play along), you might notice that there's no native X11 system of "when the clipboard changes". The flow is Set/Get on Ctrl+C/Ctrl+V, along with this magical clipboard manager that happens on app exit so we don't lose data. But fear not; although it is undocumented in those manuals, we added this as part of the amazing XFixes extension with selection events. I don't know how it works in Python, but in C, you call XFixesSelectSelectionInput to retrieve events for the SetSelectionOwner event, then respond to that event like any other event


You can implement global keybindings, but I wanted to make sure you knew what you were doing. Hooking into Ctrl+C isn't the correct way to do it (you could use Edit->Copy or a right-click menu or something else like that), and it's difficult if you want to do something when the key is pressed, and also deliver it to the window normally. You would do this with XGrabKey on the root window, then listen for KeyPress/KeyRelease events. To also send it to the application as a pass-through, you need to use GrabSync, then from within the handler use XAllowEvents with ReplayKeyboard. When you retrieve this, you want to take the clipboard for yourself, so you want to XSetSelectionOwner and then respond to the SelectionNotify/SelectionRequest events like a normal conforming client. I'm not exactly sure how the Python Xlib bindings work, though; I'm used to the C API.

Oh, and if you have any questions, feel free to ask, as it's probably going to look like a monumental task at first, and the ICCCM and Xlib manuals aren't the easiest reading material if you don't understand the core concepts. Even if it seems like the dumbest question in the world, I've asked much dumber to understand this stuff.

As some advice on how to start, I'd make a simple app that uses the low-level Xlib to implement a simple thing that copies/pastes correctly with gedit. That should get you familiar enough with how X selections and events work, enough to go from there to implementing the XFixes events so you know when another app copies something to the clipboard, and then from there to "pasting" into the web service whenever the selection changes, and from there implementing the key press to "copy" it back into the local machine.

It seems like a cool project, so I'd be interesting in hearing your progress, too!

Boooooooooom thank you so much, it has been extremely difficult to find information on this anywhere -- I was about to stumble into IRC and try to pull teeth from some dudes. I will almost certainly be back with questions, thanks for the tips.

MeruFM
Jul 27, 2010

MeruFM posted:

Does anyone have experience building an exe with Chaco?

Nevermind again. Found the issue.
There's some dynamic imports that the builders cannot detect.

For anyone interested, I had to include in the build script:
pyface
pyface.ui.wx
enable
enable.wx
traitsui

Dominoes
Sep 20, 2007

Python code:
x = int('10.0')
Anyone know why I'm getting a "ValueError: invalid literal for int() with base 10: '10.0" error?

This works:
Python code:
x = int(float('10.0'))
I feel like not requiring this extra step would be Pythonic / duck typing.

Dominoes fucked around with this message at 01:10 on Aug 7, 2013

BeefofAges
Jun 5, 2004

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

You could try just using ast.literal_eval().

There's also the decimal module.

BeefofAges fucked around with this message at 01:21 on Aug 7, 2013

WeezerToon
Sep 25, 2011

E: misread post

WeezerToon fucked around with this message at 01:57 on Aug 7, 2013

Dominoes
Sep 20, 2007

WeezerToon posted:

Does x = float("10.0") not work for the same job?
It returns a float. This came up due to a stock broker API returning quantity as a string with decimal and 0. ie "10.0".

Opinion Haver
Apr 9, 2007

Dominoes posted:

I feel like not requiring this extra step would be Pythonic / duck typing.
The reason you need the extra step is that '10.0' doesn't denote a valid integer any more than '10+0' or '9+1' does.

xtal
Jan 9, 2011

by Fluffdaddy
10.0 isn't an integer. To coerce it would be implicit rather than explicit.

Dominoes
Sep 20, 2007

xtal posted:

10.0 isn't an integer. To coerce it would be implicit rather than explicit.
int(10.0) works though.

xtal
Jan 9, 2011

by Fluffdaddy

Dominoes posted:

int(10.0) works though.

That's very slightly more explicit.

FoiledAgain
May 6, 2007

Dominoes posted:

Python code:
x = int('10.0')
Anyone know why I'm getting a "ValueError: invalid literal for int() with base 10: '10.0" error?

This works:
Python code:
x = int(float('10.0'))
I feel like not requiring this extra step would be Pythonic / duck typing.

That's just how the builtin int() function works, according to the documentation. You can give it an integer, a float, or a string representing an integer, but not a string representing a float.

digitalcamo
Jul 11, 2013
I'm sure I'm not reading my code correctly and have something where it should be but can't seem to figure out what's wrong with it.

code:

original = raw_input('Enter a word:')

if len(original) != 0 and original.isalpha() == True:
	word = original.lower()
	first = word[0]
	if first == "a, e, i, o, u":
		print 'vowel'
	else:
		print 'consonant'
else:
	print 'empty'
The program is supposed to ask for a word and if it start with a vowel it should print vowel. If the word doesn't start with a vowel it should print consonant. The problem I'm having is no matter what word I put in it, it print 'consonant'.

Using codecademy for this program and the things is it didn't say anything was wrong with my code.

dagonis
Dec 21, 2006

Get Money
Fuck bitches
Burn Heretics

digitalcamo posted:

I'm sure I'm not reading my code correctly and have something where it should be but can't seem to figure out what's wrong with it.

code:

original = raw_input('Enter a word:')

if len(original) != 0 and original.isalpha() == True:
	word = original.lower()
	first = word[0]
	if first == "a, e, i, o, u":
		print 'vowel'
	else:
		print 'consonant'
else:
	print 'empty'
The program is supposed to ask for a word and if it start with a vowel it should print vowel. If the word doesn't start with a vowel it should print consonant. The problem I'm having is no matter what word I put in it, it print 'consonant'.

Using codecademy for this program and the things is it didn't say anything was wrong with my code.

I am not a Python genius, but I suspect that python is treating "a, e, i, o, u" as a single string, not as a series of possible values.

I changed the code a little bit and it works for me.

code:
original = raw_input('Enter a word:')

if len(original) != 0 and original.isalpha() == True:
        word = original.lower()
        first = word[0]
        if first == ("a" or "e" or "i" or "o" or "u"):
                print 'vowel'
        else:
                print 'consonant'
else:
        print 'empty'
$ python sa.py
Enter a word:apple
vowel

Got bored, here is the oneliner for this:
[('vowel' if x in 'aeiou' else 'consonant' if x not in "aeiou" else 'empty') if x.isalpha() == True and len(x) != 0 else Pass for x in raw_input('Enter a word:').lower()[0]][0]

Dies if you give it nothing, but I am too lazy to fix that now.

dagonis fucked around with this message at 03:13 on Aug 7, 2013

BeefofAges
Jun 5, 2004

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

if first in ['a', 'e', 'i', 'o', 'u']:

or

if first in "aeiou":



Also, instead of

if len(original) != 0 and original.isalpha() == True:

just do

if len(original) and original.isalpha():

or alternatively, don't check the length or whether it's an alphabetic character, just assume that it is and catch the exception if it isn't.

BeefofAges fucked around with this message at 02:44 on Aug 7, 2013

salisbury shake
Dec 27, 2011

digitalcamo posted:

I'm sure I'm not reading my code correctly and have something where it should be but can't seem to figure out what's wrong with it.

code:

original = raw_input('Enter a word:')

if len(original) != 0 and original.isalpha() == True:
	word = original.lower()
	first = word[0]
	if first == "a, e, i, o, u":
		print 'vowel'
	else:
		print 'consonant'
else:
	print 'empty'
The program is supposed to ask for a word and if it start with a vowel it should print vowel. If the word doesn't start with a vowel it should print consonant. The problem I'm having is no matter what word I put in it, it print 'consonant'.

Using codecademy for this program and the things is it didn't say anything was wrong with my code.

In your comparison you are making two mistakes that jump out right away:
1) Testing equivalency when you intend to be testing membership.
2) Using a string to hold a list.

One way to do it:
code:
vowels = ['a', 'e', 'i', 'o', 'u']
This creates a list of vowels and assigns variable vowels to it.

code:
if first in vowels:


Here we use pythons in keyword to test membership of first in the list vowels.

Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug

dagonis posted:

I changed the code a little bit and it works for me.

code:
        if first == ("a" or "e" or "i" or "o" or "u"):
                print 'vowel'
        else:
                print 'consonant'
$ python sa.py
Enter a word:apple
vowel

This worked for you because 'apple' starts with 'a'.

Python code:
>>> ("a" or "e" or "i" or "o" or "u")
'a'
>>> first = 'e'
>>> first == ("a" or "e" or "i" or "o" or "u")
False

dagonis
Dec 21, 2006

Get Money
Fuck bitches
Burn Heretics

Lysidas posted:

This worked for you because 'apple' starts with 'a'.

Python code:
>>> ("a" or "e" or "i" or "o" or "u")
'a'
>>> first = 'e'
>>> first == ("a" or "e" or "i" or "o" or "u")
False

Looking at it now, the problem is pretty obvious, thanks for pointing that out. My ugly oneliner seems to work

[('vowel' if x in 'aeiou' else 'consonant' if x not in "aeiou" else 'empty') if x.isalpha() == True and len(x) != 0 else 'Invalid Input' for x in raw_input('Enter a word:').lower()[0]][0]

dagonis fucked around with this message at 03:24 on Aug 7, 2013

digitalcamo
Jul 11, 2013
Ok thanks I got it working.

code:
if first in 'aeiou':
That piece worked for me. Didn't know about the in function. Not sure if it's even called a function. I'll have to do a little research on that one. Thanks for the help.

Haystack
Jan 23, 2005





in is a keyword, much like if, for, def, etc. It tests if the element on the left is contained within a sequence to the right. Since python treats strings as sequences, you can use in to see if a substring is in another string. Thus:

Python code:
'e' in 'aeiou'  # True
'x' in 'aeiou'  # False
'ae' in 'aeiou'  # True
'ai' in 'aeiou'  # False

object in [object, Exception]  # True
str in [object, Exception]  # False
And so on.

digitalcamo
Jul 11, 2013
Ah I see, simple enough. When I read Python code it sometimes seems as though I'm reading English. However, I only get that feeling when I actually understand the code I'm reading.

ATM Machine
Aug 20, 2007

I paid $5 for this
On the topic of if x in y, would there happen to be an anagram library of some sort that can take strings from a list, then mutate the input string to see if it matches the list string?

To give a context, I'm trying to do a trigram search on a string in an attempt to find a match and suggest a working decryption key.

Nippashish
Nov 2, 2005

Let me see you dance!

ATM Machine posted:

On the topic of if x in y, would there happen to be an anagram library of some sort that can take strings from a list, then mutate the input string to see if it matches the list string?

I don't know if I actually understand what you're asking, but can't you just sort the letters in all the strings and then compare normally?

BeefofAges
Jun 5, 2004

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

Write your mutator function as a generator function that takes a string as input. Then you can use "in" with it.

Dominoes
Sep 20, 2007

BeefofAges posted:

Also, instead of

if len(original) != 0 and original.isalpha() == True:

just do

if len(original) and original.isalpha():
if original and original.isalpha():

NtotheTC
Dec 31, 2007


Dominoes posted:

if original and original.isalpha():

I'd avoid doing this. Using the plain if statement on variables that aren't a bool strikes me as a hideous pattern despite it being perfectly legal for strings/dicts/lists/etc. You'll occasionally get nasty unexpected behaviour, not to mention it's very un-pythonic in terms of explicity. I dislike the "if len()" one too, however you'll never convince people not take shortcuts like this with dynamic-typed languages.

NtotheTC fucked around with this message at 16:33 on Aug 8, 2013

deimos
Nov 30, 2006

Forget it man this bat is whack, it's got poobrain!

NtotheTC posted:

I'd avoid doing this. Using the plain if statement on variables that aren't a bool strikes me as a hideous pattern despite it being perfectly legal for strings/dicts/lists/etc. You'll occasionally get nasty unexpected behaviour, not to mention it's very un-pythonic in terms of explicity. I dislike the "if len()" one too, however you'll never convince people not take shortcuts like this with dynamic-typed languages.

This is only true if you don't know the side effects of your statements or the definition of what is False

NtotheTC
Dec 31, 2007


deimos posted:

This is only true if you don't know the side effects of your statements or the definition of what is False

Well quite, and wouldn't the world be a nice place if we all understood the side effects at every stage of our writing/maintaining code. My feeling is that if you're trying to test for something being greater than 0 (in this case the length of a string) then it's more pythonic to say so directly with:

code:
if len(original) > 0:
(you can argue that you're trying to test for the "existence" of a string in that example rather than it's length, but I'd disagree on technical grounds because you know raw_input is going to return a string no matter what and so really it's just the length you're concerned with).

Again, I'm all about the readability with this. Your way isn't going to cause the sky to fall, and 9 times out of 10 it will never cause a problem. But why leave it open and sacrifice (in my opinion) prettiness/readability just so you can type 5 less characters?

NtotheTC fucked around with this message at 17:04 on Aug 8, 2013

deimos
Nov 30, 2006

Forget it man this bat is whack, it's got poobrain!

NtotheTC posted:

Well quite, and wouldn't the world be a nice place if we all understood the side effects at every stage of our writing/maintaining code. My feeling is that if you're trying to test for something being greater than 0 (in this case the length of a string) then it's more pythonic to say so directly with:

code:
if len(original) > 0:
(you can argue that you're trying to test for the "existence" of a string in that example rather than it's length, but I'd disagree on technical grounds because you know raw_input is going to return a string no matter what and so really it's just the length you're concerned with).

Again, I'm all about the readability with this. Your way isn't going to cause the sky to fall, and 9 times out of 10 it will never cause a problem. But why leave it open and sacrifice (in my opinion) prettiness/readability just so you can type 5 less characters?

code:
>>> if len(x) > 0:
...     print "string has content"
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: object of type 'NoneType' has no len()
Personally if I am checking if a list has any elements at all I'd omit len() and >0. I am checking for validity. If I were checking for something else I wouldn't omit them (at least X elements, less than X elements, etc).

deimos fucked around with this message at 17:16 on Aug 8, 2013

Thermopyle
Jul 1, 2003

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

code:
None
efb

NtotheTC
Dec 31, 2007


deimos posted:

code:
>>> if len(x) > 0:
...     print "string has content"
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: object of type 'NoneType' has no len()

code:
>>> x = raw_input("x: ")
x: 
>>> if len(x) > 0:
...     print "string has content"
... 
>>> 
If you're worried about a string being None use

code:
if x not in ['', None]:

Thermopyle
Jul 1, 2003

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

NtotheTC posted:

If you're worried about a string being None use

code:
if x not in ['', None]:

Or just do it the way the whole Python community does.

NtotheTC
Dec 31, 2007


I'm not going to get into a community best practice slap fight. I just view this in a similar light to:

code:
x = None

if x:
    pass

# vs

if x is None:
    pass
(the bottom one is more pythonic)

You're more than welcome to overrule me on this as I imagine you're more experienced with python than I am. I don't think verboseness is a bad thing to learn when it enhances readability though.

NtotheTC fucked around with this message at 17:30 on Aug 8, 2013

Adbot
ADBOT LOVES YOU

deimos
Nov 30, 2006

Forget it man this bat is whack, it's got poobrain!

NtotheTC posted:

I'm not going to get into a community best practice slap fight. I just view this in a similar light to:

code:
x = None

if x:
    pass

# vs

if x is None:
    pass
(the bottom one is more pythonic)

You're more than welcome to overrule me on this as I imagine you're more experienced with python than I am. I don't think verboseness is a bad thing to learn when it enhances readability though.

The argument you're making makes it so that you have to check at least twice to see if something has content:

Python code:
if x is not None and hasattr(x, '__len__') and len(x) > 0:
    pass

  • Locked thread