Does python have a shorthand to check if an object has an attribute? Background is I'm getting data from a JSON API where lots of fields are optional and I want most of the fields in a database. When a specific field isn't available I want an empty string ("") written into the database.  Currently I've been doing:  if jsonobject.what_i_look_for:   dbstring = jsonobject.what_i_look_for else:   dbstring = ""   And then inserted dbstring into the database. However I'm getting a lot more of these fields now and I want a much cleaner code rather than a function which consists about 80% of if-statements.  I've found  and  shorthand to check if a variable is empty, but both don't seem to work directly as a string. I've tested this using print() in an interactive python 3.5.2 shell:  &gt;&gt;&gt; print(testvar or "") Traceback (most recent call last):   File "&lt;stdin&gt;", line 1, in &lt;module&gt; NameError: name 'testvar' is not defined  &gt;&gt;&gt; print(testvar if testvar else "") Traceback (most recent call last):   File "&lt;stdin&gt;", line 1, in &lt;module&gt; NameError: name 'testvar' is not defined   This: echo (isset($testvar) ? $testvar : ""); is the PHP equivalent of what I seek.  Edit: Since it seems relevant: The object I am trying to process is coming from Telegram's JSON API. I'm using python-telegram-bot as library and  is an example object.
A get() like method for checking for Python attributes If I had a dictionary dict and I wanted to check for dict['key'] I could either do so in a try block (bleh!) or use the get() method, with False as a default value.  I'd like to do the same thing for object.attribute. That is, I already have object to return False if it hasn't been set, but then that gives me errors like     AttributeError: 'bool' object has no attribute 'attribute'
Windows 8 upgrade Recovery Disk I have upgraded to Windows 8 from Win 7. I want to create a recovery disk for Windows 8, just in case something goes wrong. I didn't find the option of creating it from the control panel.  How do I create a Recovery CD/DVD? I'm trying to make a quicklist on the Workspace Switcher launcher that allows for quick switching to a certain workspace. (My friend sometimes uses my computer and just doesn't enjoy keyboard shortcuts, so I want to help him out.)  So is there a command one could type in a terminal that would force a certain workspace to be focused on? Derive a formula to find the number of trailing zeroes in $n!$ Possible Duplicate:          I know that I have to find the number of factors of $5$'s, $25$'s, $125$'s etc. in order to do this. But how can you derive such a formula for any number $n$? Is there a reasonable statistic test one can do to standard random number generators (say, one of those that come built in in Python libs) which shows they are not really random?  (By reasonable I mean to exclude silly things like «generate a looong list and see that it is periodic»)  Later: Notice I am looking for a test that fails on standard generators. How to access QGIS Plugin Repositories from behind a proxy? I have been trying to teach myself QGIS by using this forum and others to help. Most of my questions can be answered by downloading plugins that are available through 3rd party repositories but for some reason I am not able to connect with these. Anyone have any ideas why this is the case? Canonical Post #2: What is the perfect, and how should I use it? When does a locational distinction change its suffix and capitialization in a proper name? I was coding a physics simulation, and noticed that I was using discrete time. That is, there was an update mechanism advancing the simulation for a fixed amount of time repeatedly, emulating a changing system.  I though that was interesting, and now believe the real world must behave just like my program does. It is actually advancing forward in tiny but discrete time intervals? Let There Be Light Story Identification I am looking to identify a story that I read around 2001 (it is probably much older).  Someone showed me the story on pages printed from the internet, and it was attributed to Isaac Asimov (although I cannot state that is the true author).    The story is told in glimpses at different points of time in the future.  In each glimpse, humans are asking a more and more "intelligent" computer how to prevent the universe from collapsing into a singularity in the future, and the computer states it needs more computational power and resources to solve this problem.  At some point, man becomes one with the computer, and the computer exists in hyperspace (or subspace?).    In the final glimpse, it is the end of time and the universe is collapsing into a singularity.  At the instant the universe reaches the singularity, the computer figures out how to prevent it and says "Let there be light" and the universe begins to expand again.  Is anyone familiar with this story? What software is focused on reviewing and organizing images? How can I manually create a pixel perfect image sprite? Is it possible for an encryption method to exist which is impossible to crack, even using quantum computers? Quantum computers are known to be able to crack  a broad range of cryptographic algorithms which were previously thought to be solvable only by resources increasing exponentially with the bit size of the key. An example for that is .  But, as far I know, not all problems fall into this category. On , we can read     Researchers have developed a computer algorithm that doesn’t solve problems but instead creates them for the purpose of evaluating quantum computers.   Can we still expect a new cryptographic algorithm which will be hard to crack using even a quantum computer? For clarity: the question refers to specifically to the design of new algorithms. How to encode the filename parameter of Content-Disposition header in HTTP? Web applications that want to force a resource to be downloaded rather than directly rendered in a Web browser issue a Content-Disposition header in the HTTP response of the form:  Content-Disposition: attachment; filename=FILENAME  The filename parameter can be used to suggest a name for the file into which the resource is downloaded by the browser.  (Content-Disposition), however, states in  (The Filename Parameter) that the file name can only use US-ASCII characters:     Current [RFC 2045] grammar restricts   parameter values (and hence   Content-Disposition filenames) to   US-ASCII.  We recognize the great   desirability of allowing arbitrary   character sets in filenames, but it is   beyond the scope of this document to   define the necessary mechanisms.   There is empirical evidence, nevertheless, that most popular Web browsers today seem to permit non-US-ASCII characters yet (for the lack of a standard) disagree on the encoding scheme and character set specification of the file name. Question is then, what are the various schemes and encodings employed by the popular browsers if the file name “naïvefile” (without quotes and where the third letter is U+00EF) needed to be encoded into the Content-Disposition header?  For the purpose of this question, popular browsers being:   Firefox  Internet Explorer  Safari Google Chrome  Opera tcpdump : lost packets Consider the following example:  \documentclass{article} \newtheorem{Theorem}{Theorem} \begin{document} \begin{Theorem} On the other hand, this one has only one claim. \end{Theorem} \begin{Theorem} \begin{enumerate} \item First claim \item Second claim \end{enumerate} \end{Theorem} \end{document}   Typesetting it results in:    Notice there is extra horizontal space before the first item in the list of the second theorem.     Is there a sensible way to get rid of that?   Ideally, the solution would work with amsthm, thmtools, enumitem.  N.B.: this is related to  but not quite the same. How do you explain the value of native files to an uneducated client? If you design a piece for print. It gets reproduced several times over the course of a few years. Then the client doesn't return for any work for a few more years. And suddenly you are contacted asking for native files (Indesign, Illustrator, Photoshop). As the client puts it, "We just want to be able to make minor changes, we aren't designers."  Now, there is absolutely value in the native files. They are my "secret recipe" as a designer and anyone asking for that recipe should provide compensation for the ease of reusing, repurposing, and altering the recipe.  How do you explain to this client that there is value in the native files?  How do you counter the "But we already paid for the design." argument?  Note: I know I own the files. I know my contract states I own the files. Heck even without a contract, US Copyright law states I own the files.  What I'm seeking is an elegant, less argumentative, method of explaining the file ownership to the uneducated client. Reciting legal statutes and contract clauses doesn't often make for friendly client relations. My goal is to find a method of explaining so it is fully understood by the client without the appearance of a contract clause which forces them to do something against their will. I want the client to respect and not resent these types of contract clauses. How to draw a torus Is there an easy way to draw a contour image of torus below with tikz? Or for that matter with any other graphics package. Where do I find the current C or C++ standard documents? For many questions the answer seems to be found in "the standard". However, where do we find that? Preferably online.  Googling can sometimes feel futile, again especially for the C standards, since they are drowned in the flood of discussions on programming forums.  To get this started, since these are the ones I am searching for right now, where are there good online resources for:   C89 C99 C11 C++98 C++03 C++11 C++14 C++17 The Many Memes of Meta Catchphrases and concepts that spread from person to person are known as [memes], which, courtesy the Internet, can now explode across the Earth like a highly contagious virus (hence &quot;going viral&quot;). As with their real-life counterparts, some infectious diseases are global (pandemic), while others are endemic to specific regions. Stack Overflow, and now even more predominantly Meta Stack Exchange, have seen more than their fair share of these pathological social constructs spread through the user base. They are now ingrained units of our collective culture as SOpedians (a term which I hate, by the way). Just as travelers' immune systems can be assaulted by new diseases in new places, new users are increasingly likely to be miffed by an ingrained meme and left sitting scratching their heads. I therefore propose that this space be used to document the memes endemic to Stack Exchange's culture. Each meme should be listed in a separate answer and I hope that we as a community will be able to provide greater context to each one. Please actually explain each meme in a way understandable to those not already in the know. Especially considering that a lot of these memes aren't really understandable to newer users who weren't around in the early years of the network, or are based on system features that no longer exist.  On other Stack Exchange sites          [memes]: Post Feedback link is broken I first noticed this a while back. But it has yet to resolve itself.  When I click on the  in the 10k tools, it hangs for a while.Then it gives me an error message: