I want to break this code:  ex = func(object) if not self.is_object() else foo()   to multiple lines (pep 8). What is the best way to do it? I thought about this:  ex = func(object) \     if not self.is_object() \     else foo()   But this seems a bit ugly and not very neat. Is there another way?  Edit: This is different from just breaking a line into multiple lines, because this is a special "expression if stmnt else stmnt" and not just breaking any python code.
I have a long line of code that I want to break up among multiple lines. What do I use and what is the syntax?  For example, adding a bunch of strings,  e = 'a' + 'b' + 'c' + 'd'   and have it in two lines like this:  e = 'a' + 'b' +     'c' + 'd'
Replacing non-English characters in attribute tables using ArcPy and Python? I have a few shapefiles where some of the attributes contain the non-English characters ÅÄÖ. Since some queries doesn't work with these characters (specifically ), I tried to change them in advance with a simple script and add the new strings to another field.  However, change in characters works fine but not updating the field with arcpy.UpdateCursor.   What is an appropriate way of solving this?  I have also tried to do this via the Field Calculator while posting "code" to the codeblock, with the same error.  Error message: Runtime error  Traceback (most recent call last):   File "", line 1, in    File "c:/gis/python/teststring.py", line 28, in      val = code(str(prow.Typkod)) UnicodeEncodeError: 'ascii' codec can't encode character u'\xc4' in position 3: ordinal not in range(128)  Code:  # -*- coding: cp1252 -*- def code(infield):     data = ''     for i in infield: ##        print i         if i == 'Ä':             data = data + 'AE'         elif i == 'ä':             data = data + 'ae'         elif i == 'Å':             data = data + 'AA'         elif i == 'å':             data = data + 'aa'         elif i == 'Ö':             data = data + 'OE'         elif i == 'ö':             data = data + 'oe'         else:             data = data + i     return data   shp = r'O:\XXX\250000\DB\ArcView\shape.shp'  prows = arcpy.UpdateCursor(shp)  for prow in prows:     val = code(unicode(str(prow.Typkod), "utf-8"))     prow.Typkod_U = val     print val     prows.updateRow(prow)   The values of Typkod are of the type: [D, D, S, DDRÄ, TRÄ] etc.  I use ArcMap Basic (10.1) on Windows 7.    New Error message:  Runtime error  Traceback (most recent call last):   File "", line 1, in    File "c:/gis/python/teststring.py", line 29, in      val = code(unicode(str(row.Typkod), "utf-8")) UnicodeEncodeError: 'ascii' codec can't encode character u'\xc4' in position 3: ordinal not in range(128)  &gt;&gt;&gt; val 'DDRÄ' &gt;&gt;&gt; type(val) type 'str'      It appears as if the output from the function is wrong somehow. When there's ÅÄÖ involved it returns data = u'DDR\xc4' and not (as was my intention) data = 'DDRAE'. Any suggestions on what might cause this? Removing control chars (including console codes / colours) from script output I can use the "script" command to record an interactive session at the command line.  However, this includes all control characters and colour codes.  I can remove control characters (like backspace) with "col -b", but I can't find a simple way to remove the colour codes.  Note that I want to use the command line in the normal way, so don't want to disable colours there - I just want to remove them from the script output.  Also, I know can play around and try find a regexp to fix things up, but I am hoping there is a simpler (and more reliable - what if there's a code I don't know about when I develop the regexp?) solution.  To show the problem:   spl62 tmp: script Script started, file is typescript spl62 lepl: ls add-licence.sed  build-example.sh  commit-test         push-docs.sh add-licence.sh   build.sh          delete-licence.sed  setup.py asn              build-test.sh     delete-licence.sh   src build-doc.sh     clean             doc-src             test.ini spl62 lepl: exit Script done, file is typescript spl62 tmp: cat -v typescript Script started on Thu 09 Jun 2011 09:47:27 AM CLT spl62 lepl: ls^M ^[[0m^[[00madd-licence.sed^[[0m  ^[[00;32mbuild-example.sh^[[0m  ^[[00mcommit-test^[[0m         ^[[00;32mpush-docs.sh^[[0m^M ^[[00;32madd-licence.sh^[[0m   ^[[00;32mbuild.sh^[[0m          ^[[00mdelete-licence.sed^[[0m  ^[[00msetup.py^[[0m^M ^[[01;34masn^[[0m              ^[[00;32mbuild-test.sh^[[0m     ^[[00;32mdelete-licence.sh^[[0m   ^[[01;34msrc^[[0m^M ^[[00;32mbuild-doc.sh^[[0m     ^[[00;32mclean^[[0m             ^[[01;34mdoc-src^[[0m             ^[[00mtest.ini^[[0m^M spl62 lepl: exit^M  Script done on Thu 09 Jun 2011 09:47:29 AM CLT spl62 tmp: col -b &lt; typescript  Script started on Thu 09 Jun 2011 09:47:27 AM CLT spl62 lepl: ls 0m00madd-licence.sed0m  00;32mbuild-example.sh0m  00mcommit-test0m         00;32mpush-docs.sh0m 00;32madd-licence.sh0m   00;32mbuild.sh0m          00mdelete-licence.sed0m  00msetup.py0m 01;34masn0m              00;32mbuild-test.sh0m     00;32mdelete-licence.sh0m   01;34msrc0m 00;32mbuild-doc.sh0m     00;32mclean0m             01;34mdoc-src0m             00mtest.ini0m spl62 lepl: exit  Script done on Thu 09 Jun 2011 09:47:29 AM CLT Redefining "cited on" string (and others) in biblatex I'm trying to modify the strings biblatex uses to set the "cited on" string used in the bibliography to identify the pages where a given references has been cited.    What I gather from the biblatex documentation (e.g., § 4.9.2.16) is that something like   \renewbibmacro{backrefpage}{&lt;newtext&gt;} \renewbibmacro{backrefpages}{&lt;newtext&gt;}   ought to work, but they have no effect for me (I'd also like to get this working for the "visited on" string, urlseen).  My MWE is unchanged from , with the addition of these (and related lines) just about anywhere. Should I put myself last? "me and my friends" vs. "my friends and me" or "my friends and I" Why not use the Lagrangian, instead of the Hamiltonian, in nonrelativistic QM? Solutions of $x^2 \equiv 1 \pmod N$ I am stuck with this exercise:     Show that $\forall s &gt;0 \quad \exists N &gt;0$ such that $$x^2 \equiv 1\pmod N$$ has more than $s$ solutions.   I think I cannot use the theory if quadratic residues, because the modulus is not prime, so maybe I must prove it with square roots or roots of unity, but I don't know how to approach it at all.  Thanks for any help. I am downloading macOS Sierra from Mac App Store. But I have electricity problem here. Due to which my iMac will lose power after 2 hours. Now I want to pause the downloading so that I can resume the download later on. How can I do that?  Here is a screenshot. Subsubsection: remove the newline (like paragraph) Using the article document class, how can one remove the newline at the end of a subsubsection title?  I am using \documentclass{article}; I do not currently use titlesec or any of the alternatives; I do use fancyhdr. Evaluate $\lim_{x\rightarrow 0} \frac{\sin (6x)}{\sin(2x)}$ without L'Hopital How can we communicate short messages long-distance? Essentially, I wonder that if X is a plural noun, should we use a plural or singular verb in a sentence such as "X are a subject that [verb] ..."? I believe that we should always use the singular verb form there (for example, "Eatable flowers are a subject that comes up ..."). However, I was surprised to find this sentence on the  page:     Eatable flowers are a subject that come up in almost all cooking classes eventually and I am a big fan of them.   as well as this on Google Books:     Tools are a subject that come up at our house from time to time.   I think they are typos, but I would like a double check to be sure. How to find information about the system/machine in Unix? I have always found it difficult to find information about the system itself in Unix, whether it be   Which OS I am using (version number and all, to compare it with the latest available builds)? Which Desktop Environment am I using? If I am using KDE, most of the programs begin with a K and I can say I am using KDE, but there should be some way to query this, say from a script. Which kernel version am I using? (For example, I am using Fedora, and I want to know what Linux kernel version I am using)   Basically, what I miss is a single point/utility that can get all this information for me. Most of the times the solutions to the above would themselves be OS specific. Then, you are stuck. When should I use can? When should I use could? What is right under what context? I have a  to which I'd like to add JPEG and PNG images that I generate on the fly.  All the examples I've seen so far in the , specially in the  use ImageIcons.  I'm generating these images as byte arrays, and they are usually larger than the common icon they use in the examples, at 640x480.   Is there any (performance or other) problem in using the ImageIcon class to display an image that size in a JPanel? What's the usual way of doing it? How to add an image to a JPanel without using the ImageIcon class?   Edit: A more careful examination of the tutorials and the API shows that you cannot add an ImageIcon directly to a JPanel. Instead, they achieve the same effect by setting the image as an icon of a JLabel. This just doesn't feel right... How to reset Canon 70D WiFi? I'm a Georgian national holding a multiple entry Schengen visa.  Last summer I was traveling to Hungary, spent a few days there, then flew to the UK. The Hungarian border official did NOT stamp my passport on exiting the Schengen area. I had to enter it again a few days later and the German border guards were confused by what had happened. Finally they let me enter.  Now I have one more entry stamp into Schengen than exit stamp and run into problems EVERY time at a Schengen border.  Is there a way to fix this? How to split a long regular expression into multiple lines in JavaScript? Sum of closed spaces is not closed Is this statement true?      In a metric spase $(E,d)$, a sequence $(x_n)$ is Cauchy if and only if $  \forall k\in \mathbb{N}, \lim_{n\rightarrow+\infty}d(x_{n+k},x_n)=0$   I proved that $\Rightarrow$ is true,indeed if $(x_n)$ is Cauchy then for all $\varepsilon&gt;0,\exists n_0\in\mathbb{N}, \forall p,q\geq n, d(x_p,x_q)&lt;\varepsilon$ it still right for all $ n\geq n_0$ and $m=n+k&gt;n\geq n_0$   But I don't know if $\Leftarrow$ is true ? How to get the native version of Spotify running?