How to convert a string into a number? Note: despite the linked duplicate not being a duplicate (it explicitly asks about casting to int and float separately) I still mark it as duplicate because it contains wonderful information about the subject (and an answer similar to my solution) Summary: I am looking for a pythonic way to convert a string into a number (an integer or a float). I currently use a waterfall function but while it works, it is not particularly aesthetically pleasant: def convert_to_int_or_float(a):     # maybe an integer     try:         return int(a)     except ValueError:         # nope - so can be a float or a str         try:             return float(a)         except ValueError:             # must be a str             return a  for s in [&quot;0&quot;, &quot;12&quot;, &quot;-13&quot;, &quot;14.7&quot;, &quot;-14.7&quot;, &quot;hello&quot;]:     print(s, type(convert_to_int_or_float(s)))  # outputs  # 0 &lt;class 'int'&gt; # 12 &lt;class 'int'&gt; # -13 &lt;class 'int'&gt; # 14.7 &lt;class 'float'&gt; # -14.7 &lt;class 'float'&gt; # hello &lt;class 'str'&gt;  Is there a better way to do that? (ideally though a module) I had  look at math but did not find anything there.
How do I parse a string to a float or int? In Python, how can I parse a numeric string like "545.2222" to its corresponding float value, 545.2222? Or parse the string "31" to an integer, 31?  I just want to know how to parse a float str to a float, and (separately) an int str to an int.
I use OS X Mavericks and have some company storage drives mounted (using smb or cfs). (smb://username@address.path.toserver.com/directory/data). When I work with files on the drive or copy files to the drive, some hidden files are created. Most of these files start with dot-dash ._ and then the filename of the original file, like:  ._test001.png ._test002.png ._test003.png   And most of the times, the famous ._.DS_Store and .DS_Store are also there.  On my Mac, these . dot items are invisible, but my windows colleagues do see these files. How can I prevent OS X from making these strange invisible files?  On  (and other internet sources) you can find a 'defaults write' to disable the creation of .DS_Store files on your network drives. But this does not work in Mavericks:  defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true   For now I use this oneliner, but doing a rm -rf does feel wrong in this case.  find . -type f -name "._*" -exec rm "{}" \;   Edit: I don't want to delete the files or exclude them from copying. I want them not to be created in the first place.  Edit: I prefer a 'native' OS X solution over third party apps.  Edit: This questions has two answers, one for the ._ files and one for the .DS_Store files. The bounty is rewarded for dot_clean, this native command line app cleans all ._ files. Unfortunately is does not clear the .DS_Store files, this can effectively be done with Asepsis. Asepsis stores .DS_Stores in a fixed location, and not in the folder itself. How to prove that any (integer)$^{1/n}$ that isn't an integer, is irrational? Is my proof beneath perfect and complete?  I wanted to prove that for any nth root of an integer, if it's not an integer, than it's irrational: $$\begin{cases} m,n\in \mathbb{N}\\\sqrt[n]{m}\notin \mathbb{N} \end{cases}\implies \sqrt[n]{m}\notin \mathbb{Q}.$$  I start by assuming that $m^{\frac 1n}$ is rational and non-integer. So there exist  co-prime integers $a,b$ so that $$\sqrt[n]{m}=\frac{a}{b}$$ $$\implies  m=\frac{a^n}{b^n}\in\mathbb{N}.$$ But since $a$ and $b$ have no common factor, $a^n$ and $b^n$ also have no common factor. So: $$\frac{a^n}{b^n}\notin\mathbb{N},$$ a contradiction. How to work with "FIFO" in C# .NET? Caption above subtables with subcaption package breaks numbering of following table I'm fairly certain this has happened to all of us at some point: You go into a room to get something, but once you're there, you can't remember what you intended to get. It seems like a specific, common phenomenon like this must have a name, but I can't think of it. Does anyone know a name (either formal or slang) for this?  I don't want a general term like forgetfulness or absent-mindedness, which could apply to all sorts of forgetting, or a term for not being able to remember a certain word. I'm looking for a word or phrase that describes this one specific situation of forgetting what you need to get as soon as you go to get it. How does water evaporate if it doesn't boil? When the sun is out after a rain, I can see what appears to be steam rising off a wooden bridge nearby. I'm pretty sure this is water turning into a gas.  However, I thought water had to reach 100 degrees C to be able to turn into a gas.  Is there an edge case, for small amounts of water perhaps, that allows it to evaporate? How to Toggle Selected Objects Visibility with H shortcut as in Maya Is one preposition enough for multiple months? A colleague of mine has written her thesis and requested me to read and correct its grammar. I have seen some sentences like     The maximum deviation of the concentration values were obtained in the growing season, especially in May, in July, in August and in September.   As you see there is one 'in' for each month. I think that one preposition would be enough for all:     The maximum deviation of the concentration values were obtained in the growing season, especially in May, July, August and September.   Which one is more suitable? What problem does oversampling, undersampling, and SMOTE solve? NULL in MySQL (Performance & Storage) What exactly does null do performance and storage (space) wise in MySQL?  For example:  TINYINT: 1 Byte TINYINT w/NULL 1 byte + somehow stores NULL? What is JSON and what is it used for? I've looked on Wikipedia and Googled it and read the official documentation, but I still haven't got to the point where I really understand what JSON is, and why I'd use it. I have been building applications using PHP, MySQL and JavaScript / HTML for a while, and if JSON can do something to make my life easier or my code better or my user interface better, then I'd like to know about it. Can someone give me a succinct explanation? I have a Java process that opens a file using a FileReader. How can I prevent another (Java) process from opening this file, or at least notify that second process that the file is already opened? Does this automatically make the second process get an exception if the file is open (which solves my problem) or do I have to explicitly open it in the first process with some sort of flag or argument? To clarify: I have a Java app that lists a folder and opens each file in the listing for processing it. It processes each file after the other. The processing of each file consists of reading it and doing some calculations based on the contents and it takes about 2 minutes. I also have another Java app that does the same thing but instead writes on the file. What I want is to be able to run these apps at the same time so the scenario goes like this. ReadApp lists the folder and finds files A, B, C. It opens file A and starts the reading. WriteApp lists the folder and finds files A, B, C. It opens file A, sees that is is open (by an exception or whatever way) and goes to file B. ReadApp finishes file A and continues to B. It sees that it is open and continues to C. It is crucial that WriteApp doesn't write while ReadApp is reading the same file or vice versa. They are different processes. So, today is July 21st and . gives me an option to download 16.04.1 LTS. However, attempting to upgrade gets me this message -  $ sudo do-release-upgrade Checking for a new Ubuntu release No new release found   What is wrong? Does it matter that I am running apt-get update behind apt-cacher-ng?  Note: Commenting out the files in apt.conf.d that used apt-cacher-ng did not make a difference.  Edit: Explanation for possible duplicates:  deals with upgrade from 12.04LTS to 14.04LTS. My question is specific to 14.04 LTS to 16.04.1 LTS upgrade. Old answers, while good for archival purposes are less relevant in a fast changing package like ubuntu. Moreover none of the answers answer what is wrong. The link  pointed out is mentioned in one of the comments. This Q &amp; A is more helpful for people upgrading today than the work around mentioned in "". java.sql.SQLException Parameter index out of range (1 > number of parameters, which is 0) Order of evaluation in C++ function parameters QGIS Atlas generation for multiple map extents? Remove Windows entry in GRUB menu Prove $x^3 + 3 =4y(y+1)$ has no integer solutions I was just wondering whether the following statement is correct.  Let R be a ring and M a noetherian R module. Then M is finitely generated. Subdividing Causes Strange Edges / Issues on Shape