# Python Glob Windows Backslash

The backslashes escape the following character in a quoted string. Replace these N backslash(es) by 2*N+1 backslash(es) Let N be the number of backslash(es) tailing the original string, N might be zero. OLD project page for the Python extensions for Windows ## backslash as parm returns dictionary of numeric info corresponding to VS_FIXEDFILEINFO struc ! for n, v. Programming languages that have their roots in Unix and the C programming language, like Python, treat the backslash ("\") as the escape character. You can also save this page to your account. Anything afterward is passed as options to python script or command, not interpreted as an option to interpreter itself. It was created out of a frustration with the standard Python approach to files and directories, the venerable os module. For example, to build a list all the files in a pathlib. Type a backslash followed by a LaTeX style short name, such as \alpha. This is done through the inclusion of a "System Variable", commonly called the "PythonPath". So, clearly raw strings are optimized for regular expression use, and not for Windows pathname use. I often have a difficult time finding the appropriate functions to work with files and directories in Python. 4 to deal with these challenges. chdir method. By default, glob() returns GLOB_NOMATCH if there are no matches. Linux and Unix systems and shells also supports glob and also provide function glob() in system libraries. Nothing could. That's why, when you printed the filename, you got the result that you did. Listing 6: Using pathlib with the glob method. It splits the pattern into words and feeds each one to bsd_glob(). normpath(), as detailed in this blog post. (Note: news ab. class pathlib. pdf), Text File (. The most frequently used is called glob; this is the same kind of pattern matching used by the Unix shell, and should be familiar to Windows command prompt users, too. For example, the "*" glob pattern matches file name ". Note that for symbolic links, dir returns information about the file that the symbolic link points to rather than the link itself. The string replace function will not work since the backslash is an escape character. I personally avoid using double-backslashes in Windows and just use Python's handy raw-string format. The pattern may contain wildcard expressions even in intermediate directory names (e. The special operator % lets you create formatted output. packages()', which I worked around by mapping a drive letter to a UNC path. Glob follows the standard wildcard protocol. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates. This is the place to post completed Scripts/Snippets that you can ask for people to help optimize your code or just share what you have made (large or small). org's getting started page). Windows uses backward slashes to denote subdirectories, while Linux use forward slashes. Calling them either with back-tick or with system, even when writing Perl scripts. Linting Python in Visual Studio Code. pyd file the same as a DLL? How can I embed Python into a Windows application? How do I use Python for CGI?. That is, it can be used to serve up local HTML files and CGI scripts with just a standard Python install on Windows, and without connecting to the Internet at all. Just change your code to the following and you won't have to escape the backslashes: import glob files1 = glob. You can also save this page to your account. If no pattern matches, return the original pattern. A backslash in python (like many languages) is the escape character in strings. For example, the "*" glob pattern matches file name ". It was created out of a frustration with the standard Python approach to files and directories, the venerable os module. These tools apply functions to sequences and other iterables. I don't have Windows here to test it, but it should be something like that. glob(pathname)¶ Return a possibly-empty list of path names that match pathname, which must be a string containing a path specification. exec will not work well with TUI applications when a console is not present, as is done when launching applications under wish. The MS-Windows rule for double-quoting a string is the following: For each double quote in the original string, let N be the number of backslash(es) before it, N might be zero. A file-name glob can use *, ?, and […] as wildcards, and \ to quote a wildcard or backslash character literally. Windows におけるファイル名. UseVimball finish autoload/atplib. Windows Bulletin Tutorials. This is because C is the most common language for implementing secure programs on Unix-like systems (other than CGI scripts, which tend to use languages such as Perl, PHP, or Python). But the method is not working just because of those extra backslashes. No tilde expansion is done, but *, ?, and character ranges expressed with [] will be correctly matched. How do I run a Python program under Windows? How do I make Python scripts executable? Why does Python sometimes take so long to start? Where is Freeze for Windows? Is a *. 6, f-strings are a great new way to format strings. MathWorks is the leading developer of mathematical computing software for engineers and scientists. Notice that the ~username form does not work on Jython or on Windows python 2. According to 10. path — Common pathname manipulations¶ This module implements some useful functions on pathnames. the 7 line webserver. A tech blog about fun things with Python and embedded electronics. I'm not sure if this program is available on windows, try changing it to notepad. Global Functions and Features¶ Importing other Sikuli Scripts (reuse code and images) ¶ When getting more experienced with scripting or when you are used to structure your solutions into a modular system, you might want to have access to the related features of the programming environment - in this case the Python/Jython features of module. ) The -ex flag may be used to protect patterns that might otherwise match interact flags from doing so. This option treats glob patterns *. The same is true for Python strings. 0 and CP/M where the slash was the command-line option indicator. Why an object-oriented API. This difference can lead to hard-to-spot errors, such as our first example in the introduction working for only Windows paths. In computing, echo is a command that outputs the strings it is being passed as arguments. Windows also has a mechanism for starting up new processes. Outside of recipe lines, backslash/newlines are converted into a single space character. Windows Only Extensions XML Manipulation GUI Extensions Keyboard Shortcuts? This help j Next menu item k Previous menu item g p Previous man page g n Next man page G Scroll to bottom g g Scroll to top g h Goto homepage g s Goto search (current page) / Focus search box. join pick others. The program uses glob. In JavaScript, regular expressions are also objects. Because this is a raw string, Python considers the backslash as part of the string and not as the start of an escape character. Numerical computing in Python, with particular. Paths and ROS. pathname can be either absolute (like /usr/src/Python-1. By default, string matching is exact with no wild cards. GLOB_NOESCAPE Don't allow backslash ('\') to be used as an escape character. String literals may optionally be prefixed with a letter r' or R'; such strings are called raw strings and use different rules for backslash escape sequences. Generally speaking, in Bash, a ? is a glob pattern that expands to an arbitrary character. Campbell, Jr. Sipos * Antony Lee * Aron Ahmadia * Benedikt Sauer * Benjamin Jones * Benjamin Ragan-Kelley * Benjie Chen * Boris de Laage * Brad Reisfeld * Bradley M. LOG that contains a list of actions taken during the install. system() when dealing with system administration tasks in Python. As an alternative, we can retrieve files by matching their filenames by using something called a glob. The backslash as path separator comes from the lineage of CP/M, DOS, and Windows. The UID/PWD keywords are for SQL Server Authentication which uses a completely independent set of credentials from Windows logins etc. Calling them either with back-tick or with system, even when writing Perl scripts. Not only are. -fd://123 - Read data from the given UNIX FD (for example 123). txt Note サンプルコードを実行したいなら、これらのファイルを作成するために glob_maketestdata. path Examples This Python article uses path methods found in the os. 40 10 Jan 2019. Bash Shell and Beyond. It takes two operands: a formatted string and a value. As an alternative, we can retrieve files by matching their filenames by using something called a glob. py) to execute - read from stdin. GLOB_NOESCAPE - Backslashes do not quote metacharacters GLOB_BRACE - Expands {a,b,c} to match 'a', 'b', or 'c' GLOB_ONLYDIR - Return only directory entries which match the pattern GLOB_ERR - Stop on read errors (like unreadable directories), by default errors are ignored. When did Windows start accepting the forward slash as a path separator character? At one time, it was accepted as a truism that Windows (like MS-DOS) was different from Unix because Windows used the backslash as the path separator character, whereas Unix used the forward slash. Windows filenames used a backslash as a separator, but within Python the backslash had the magic power of an escape character, so every time she wanted a backslash in a filename she had to code two backslashes, like this:. Python 2 is reaching its End Of Life (EOL) in 2020 so sometime before then I will want to shift SOFA to Python 3. It is useful in any situation where your program needs to look for a list of files on the filesystem with names matching a pattern. Python Forums on Bytes. exec on Unix-like systems, and enables you to do something similar on Windows platforms. They are extracted from open source Python projects. 39 ] CVSROOT: /cvs Module name: src Changes by: [email protected] OLD project page for the Python extensions for Windows ## backslash as parm returns dictionary of numeric info corresponding to VS_FIXEDFILEINFO struc ! for n, v. The following program was tested in a DOS window under Windows/XP and should work for all Microsoft Windows. argv[1:]) => If no script or command, Python enters interactive mode. perlfaq5 NAME. " Vimball Archiver by Charles E. In Windows , backslashes are used to separate directories in file paths (ex: C:\Program Files\Common Files\microsoft shared\ ). /S (none) Selects matching files in subdirectories. Se questo è un Python 3 & unicode problema, io suggerisco di provare a correggere la stringa prima: path = "\\\\myshare\folder" path = bytes (path, "utf-8"). The way in which backslash/newline combinations are handled depends on whether the statement is a recipe line or a non-recipe line. glob(r'C:\A\*. This method returns a string, which is the concatenation of the strings in the sequence seq. Closes support request #106504. We recommend downloading Anaconda's latest Python 3 version. FORCEWIN, glob. I used awk until I learned Python (long ago). Pythonwin - LVITEM and TVITEM conversions use PyWinobject_AsTCHAR, result needs to be freed xxx win32uimodule - Python_callback has 64-bit issues with HWND, WPARAM, LPARAM xxx win32util. This is another way to protect your filenames from interpretation. replace(str, '\\', '/'), but also creating a method manually to search through the string and replace the instances, and both do not work. bpo-27952: Get Tools/scripts/fixcid. a backslash in a regular expression has to be written as a double backslash, because the backslash functions as an escape character in regular expressions. Skip any command-line file with a name suffix that matches the pattern glob, using wildcard matching; a name suffix is either the whole name, or any suffix starting after a ‘/’ and before a non-‘/’. fork and os. Note that for symbolic links, dir returns information about the file that the symbolic link points to rather than the link itself. UNIX shell scripting with ksh/bash The goals of this class are to enable you to: Learn what kinds of problems are suited to shell scripts Review the most commonly used Unix commands that are useful in shell scripts. The pattern may contain wildcard expressions even in intermediate directory names (e. normpath(), as it did originally the library, but that converted all cases to lower under Windows (not on POSIX). gif), and can contain shell-style wildcards. def commonprefix(m): "Given a list of pathnames, returns the longest common leading component" if not m: return '' # Some people pass in a list of pathname parts to operate in an OS-agnostic # fashion; don't try to translate in that case as that's an abuse of the # API and they are already doing what they need to be OS-agnostic and so # they most likely won't be using an os. txt') files2 = glob. I personally avoid using double-backslashes in Windows and just use Python's handy raw-string format. Any filenames that match the glob are. I could've sworn python had such a command, but now I can't find it I'm looking for an easy way to perform a UNIX-style "touch", to update the modification time of a file without actually modifying it. glob - Unix style pathname pattern expansion - Python 2. If no flags argument is give then GLOB_CSH is set, and on VMS and Windows systems, GLOB. And it is why Python couldn't find your file — because no file with the name. Advanced Search Ant glob syntax absolute path. (6 replies) It does not, although *you* are not escaping the backslash yourself, and that is dangerous. By default, string matching is exact with no wild cards. It provides a simple graphical interface for editing and running Python programs on computers running the Microsoft Windows operating systems. - Update python manual page (options -B, -O0, -s, environment variables PYTHONDONTWRITEBYTECODE, PYTHONNOUSERSITE). The Pathlib module in Python simplifies the way in working with files and folders. The new Windows terminal app is now available in the Microsoft Store which means anyone can try it out. Free Software. The most frequently used is called glob; this is the same kind of pattern matching used by the Unix shell, and should be familiar to Windows command prompt users, too. Installing modules: the install command family¶. Example 3: Sort the list using sorted() having a key function. If dst is a file or. As python provides a lot of functionalities we can remove files and directories according our needs. You can create a new interpreter or use one of the existing interpreters. It doesn't matter whether people view the "line" as continuing; they do immediately recognize that the expression needs to be closed before the statement can end. For Windows users, this is fairly complex: involving copying obscure DLL’s to the system folder and so on. It combines the best of Python's file system modules namely os, os. Tk is the standard GUI not only for Tcl, but for many other dynamic languages, and can produce rich, native applications that run unchanged across Windows, Mac OS X, Linux and more. The following program was tested in a DOS window under Windows/XP and should work for all Microsoft Windows. script is the name of a python file (. Advertisements. By default, string matching is exact with no wild cards. In Python, most of the scripts involve interacting with file. So I would: a) drop the test checking for equality b) consider returns-not-unicode a failure only if os. To successfully complete this tutorial you'll need to know the basics of Python (you can get started at python. You can find important information about your location or about the process. txt If you've been paying attention to what the backslash character means for Python strings, you might remember that it acts as an escape sequence - i. You have a few options: 1) You can use a raw string (r"stringgoeshere"), or os. In this tutorial we will look glob() function usage in Python programming language. glob (pathname) ¶ Return a possibly-empty list of path names that match pathname, which must be a string containing a path specification. pdf), Text File (. On Windows, both slash (/) and backslash (\) are used as directory separator character. The following are code examples for showing how to use os. The main reason for that, was that I thought that was the simplest way of running Linux commands. py in Python to double or quadruple or octuple or zzzuple your backslashes. Python's built-in "re" module provides excellent support for regular expressions, with a modern and complete regex flavor. If you want a "real" C open(2), then you should use the sysopen function, which involves no such magic (but uses different filemodes than Perl open, which corresponds to C fopen(3)). UseVimball finish autoload/atplib. Datacamp provides online interactive courses that combine interactive coding challenges with videos from top instructors in the field. 3 branch is a +descendant of the 3. August 30, 2014, 4:27am #1. The easy solution is to escape the backslashes like this: "C:\\data\\". Windows uses backward slashes to denote subdirectories, while Linux use forward slashes. isHidden(java. OLD project page for the Python extensions for Windows ## backslash as parm returns dictionary of numeric info corresponding to VS_FIXEDFILEINFO struc ! for n, v. vim [[[1 685 " Title: Vim library for ATP filetype plugin. By default, string matching is exact with no wild cards. For example, \\ will represent the \ character itself and \" means the " character literary. - Issue #8980: Fixed a failure in distutils. In Python, whenever we need a filename, we can include some or all of a directory path as well. Python on Windows FAQ. In Windows, there are a couple additional ways of referencing a file. Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java and XML. Input to the parser is a stream of tokens, generated by the lexical analyzer. I want to delete said directory. Contributors to the Python Documentation Many people have contributed to the Python language, the Python standard library, and the Python documentation. When specifying Microsoft Windows file paths in Jython you must be aware of these special conditions. None of them support escaping. It is useful in any situation where your program needs to look for a list of files on the filesystem with names matching a pattern. now for making the tool i want it. 5/Makefile) or relative (like. They are extracted from open source Python projects. Python allows using both in a Windows system, but there are a couple of pitfalls to watch out for. This way we can only retrieve the files we want. Installing from source on Windows is a much more difficult prospect than installing from source on other OSs, as not only are you likely to need to compile HDF5 from source, everything must be built with the correct version of Visual Studio. Using len it works out the number of pages in the PDF. Examples: String literals in C and Python: \\ is a literal backslash. To sum them up: Python lets you use OS-X/Linux style slashes "/" even in Windows. So I decided to put this reference page up. POSIX FLAGS. Mercurial supports two kinds of pattern syntax. - Issue #7589: Only build the nis module when the correct header files are found. It is a command available in various operating system shells and typically used in shell scripts and batch files to output status text to the screen or a computer file, or as a source part of a pipeline. Most of the time, windows has no problem with a path with mixed \, \\, or / literals. Windows filenames used a backslash as a separator, but within Python the backslash had the magic power of an escape character, so every time she wanted a backslash in a filename she had to code two backslashes, like this:. Note that, for obvious reasons, escaping characters in a pattern with a backslash does not work in Windows-style paths. Windows users: If installing Python 3. edu O’Reilly Open Source Conference July 17, 2000 O’Reilly OSCON 2000, Advanced Python Programming, Slide 1 July 17, 2000, [email protected] You can create a key named after your application with a default string value giving the root directory path of your appl. In one of them, I can type Tcl code and open the file test. Calderón prometió no solo no subir la gasolina en su campaña, hizo la promesa de bajar los precios de los energéticos en general, gasolina, luz y gas. Note the double backslash is the escaped representation, the actual path only has one backslash. -1 because this advice only applies to Python string literals. has_magic(). That means that \\ (a pair of backslashes) should be interpreted as one literal backslash. Remember that Python’s string literals also use a backslash followed by numbers to allow including arbitrary characters in a string, so be sure to use a raw string when incorporating backreferences in a RE. And in this post, you’ll get to see some unique ways to copy a file in Python. (The Perl package doesn't work on Windows at all since it defers to the system fnmatch(). the 7 line webserver. The former will only match files with a dot in their name, while the latter will match even those with no dot or extension. Returns a normalized absolutized version of the pathname path. Python allows using both in a Windows system, but there are a couple of pitfalls to watch out for. Python method listdir() returns a list containing the names of the entries in the directory given by path. There were previous implementations of glob, e. Any way to change my string into a r… Trying to replace the backslash character in a string obtained with the rs. Many people who come from the world of system administration and Unix or Linux scripting, will try to keep using the regular unix commands of rm, cp and mv for these operations. because this means that you want to glob on the remote. We can also use the Python regex for this as already mentioned. You must run py2exe on a Windows computer. glob incorrect results under windows when pathname exists #26992: 64-bit Python 2. The fact is that Windows' use of backslash as the path separator conflicts with Python's use of backslashes. You can ignore case distinctions in both the PATTERN and the input files with -i optoon i. Listing 6: Using pathlib with the glob method. = 0 /*default result in case ADDRESS fails. Proposal #1 (Noam Raphael) The source can be found in AlternativePathModule. I think one reason is because the Library Reference puts seemingly related functions in two different places: 11 File and Directory Access and 14. There was only one problem. The same is true for Python strings. These tools apply functions to sequences and other iterables. now for making the tool i want it. Line 17: The createParser function takes two arguments: the unicode string containing the file name, and the plain text file name string. Use forward slashes "/" or os. #26968: glob. It's not quite a simple as installing the newest version however, so let's make sure you get the right tools for the task at hand. - Switch to OpenSSL 0. It seems to handle this by simply disabling. First up is a discussion of the basic data types that are built into Python. If you'd rather use raw strings, and special-. Examples Reading Excel (. Although the syntax accepted by this package is similar to the Perl programming language, knowledge of Perl is not a prerequisite. It is desirable to have console applications hidden and detached. The directory path uses a forward slash without mentioning operating system. The Pathlib module in Python simplifies the way in working with files and folders. It is an improved version of the vi editor distributed with most UNIX systems. The separator between elements is the string providing this method. If I open this file, its code is executed. (Unix only). Python 2 code indented with a mixture of tabs and spaces should be converted to using spaces exclusively. pathname can be either absolute (like /usr/src/Python-1. Python is an extremely readable and versatile programming language. The Internet URL path separator was chosen to be the slash since most of the developers of the standards where familiar with Unix. This free regular expression tester lets you test your regular expressions against any entry of your choice and clearly highlights all matches. It's not quite a simple as installing the newest version however, so let's make sure you get the right tools for the task at hand. Datacamp has beginner to advanced Python training that programmers of all levels benefit from. The pattern " C:\\foo\\* " is interpreted as " C:\foo\* " where " \f " will match the single character " f " and " \* " will match the single character " * " and will not be. glob(r'C:\A\*. real python part 1. Python functionality, including file handling, data structures, functions, and. glob (pathname, *, recursive=False) ¶ Return a possibly-empty list of path names that match pathname, which must be a string containing a path specification. Installing GDAL/OGR for Python on Windows is now even easier! If you are doing Python development, you may be interested in my Windows Dev Stack, which describes my development environment from high level technologies down to specific apps, and how they all work together. The files module for Python provides an easy way to deal with files, directories, and paths in a Pythonic way. py working with Python 3 and the current “re” module, avoid invalid Python backslash escapes, and fix a bug parsing escaped C quote signs. I used awk until I learned Python (long ago). The docs should indeed be clarified by changing the wording to indicate that fnmatch calls normcase but fnmatchcase does not, with a link to normcase (which in turn documents the windows behavior). DONOTEDITTHISFILE!!!!! !!!!!$!!!!!///// !!!"!&!&!+!+!S!T![!^!!k!p!y! !!!"""'" !!!&& !!!'/'notfoundin"%s" !!!) !!!5" !!!9" !!!EOFinsymboltable !!!NOTICE. Python on Windows FAQ. exe as a windowed app then python will not get the output. Since the shell's main job is to parse text, a pure shell solution was possible for string operations found in. Mac OS X, and Windows. Trying to replace the backslash character in a string obtained with the rs. pathname can be either absolute (like /usr/src/Python-1. When searching recursively, skip any subfile whose base name matches glob; the base name is the part after the last ‘/’. Glob follows the standard wildcard protocol. I have completely changed how we do stat on Windows, plus absolute path calculations, so that we follow closer Java 7 Path support and don't use JNR. GLOB_APPEND Append the results of this call to the vector of results returned by a previous call to glob(). This is because C is the most common language for implementing secure programs on Unix-like systems (other than CGI scripts, which tend to use languages such as Perl, PHP, or Python). Windows native command prompt in WinXP/2k, without Gary Bishop’s extensions. Escape sequences and escape characters From CodeCodex Escape characters (also called escape sequences or escape codes) are used to signal an alternative interpretation of a series of characters. Advertisements. This hachoir tutorial will teach you how to find mime type data for your files using Python. On Windows first search for Registry key HKEY_LOCAL_MACHINE\Software\Python\PythonCore\x. I often have a difficult time finding the appropriate functions to work with files and directories in Python. the 7 line webserver. In a previous article, I presented shell functions which emulate C functions strcat(3), strcpy(3), strlen(3), and strcmp(3). One can remove the special meaning of ?, * and [by preceding them by a backslash (except within a character class). Pandoc first tries to find the executable (searching the path if path isn't given). The MS-Windows rule for double-quoting a string is the following: For each double quote in the original string, let N be the number of backslash(es) before it, N might be zero. /S (none) Selects matching files in subdirectories. Programming languages that have their roots in Unix and the C programming language, like Python, treat the backslash ("\") as the escape character. x realms, the branch for a feature version is always a +descendant of the previous feature version: for example, the `3. This is horrible. def commonprefix(m): "Given a list of pathnames, returns the longest common leading component" if not m: return '' # Some people pass in a list of pathname parts to operate in an OS-agnostic # fashion; don't try to translate in that case as that's an abuse of the # API and they are already doing what they need to be OS-agnostic and so # they most likely won't be using an os. Lexical analysis¶ A Python program is read by a parser. I'm not sure if this program is available on windows, try changing it to notepad. Windows uses backslashes for paths, while everything else seems to use forward slashes. Python is needed on the computer where py2exe itself is run because py2exe is a Python program and it includes parts of Python in the package that is built. FORCEWIN, glob. The mainstream Python implementation, also known as CPython, is written in C compliant to the C89 standard, and is distributed with a large standard library written in a mixture of C and Python. In Windows, there are a couple additional ways of referencing a file. I personally avoid using double-backslashes in Windows and just use Python's handy raw-string format. As you have discovered, Windows paths contain a single backslash, but in Python a single backslash is an escape character. Full text of "Python Essential Reference, Fourth Edition ( 2009) David Beazley" See other formats. Python Forums on Bytes. GLOB_MARK - Adds a slash to each item returned; GLOB_NOSORT - Return files as they appear in the directory (unsorted) GLOB_NOCHECK - Returns the search pattern if no match were found; GLOB_NOESCAPE - Backslashes do not quote metacharacters; GLOB_BRACE - Expands {a,b,c} to match 'a', 'b', or 'c' GLOB_ONLYDIR - Return only directories which match. Why an object-oriented API. 4 on OSX or Windows, pyzmq has eggs and wheels that include ZeroMQ itself. PurePath e. This free regular expression tester lets you test your regular expressions against any entry of your choice and clearly highlights all matches. glob (pathname, *, recursive=False) ¶ Return a possibly-empty list of path names that match pathname, which must be a string containing a path specification. It is JavaScript based and uses XRegExp library for enhanced features. normpath(), as it did originally the library, but that converted all cases to lower under Windows (not on POSIX). The fact-checkers, whose work is more and more important for those who prefer facts over lies, police the line between fact and falsehood on a day-to-day basis, and do a great job. Today, my small contribution is to pass along a very good overview that reflects on one of Trump’s favorite overarching falsehoods. Namely: Trump describes an America in which everything was going down the tubes under Obama, which is why we needed Trump to make America great again. And he claims that this project has come to fruition, with America setting records for prosperity under his leadership and guidance. “Obama bad; Trump good” is pretty much his analysis in all areas and measurement of U.S. activity, especially economically. Even if this were true, it would reflect poorly on Trump’s character, but it has the added problem of being false, a big lie made up of many small ones. Personally, I don’t assume that all economic measurements directly reflect the leadership of whoever occupies the Oval Office, nor am I smart enough to figure out what causes what in the economy. But the idea that presidents get the credit or the blame for the economy during their tenure is a political fact of life. Trump, in his adorable, immodest mendacity, not only claims credit for everything good that happens in the economy, but tells people, literally and specifically, that they have to vote for him even if they hate him, because without his guidance, their 401(k) accounts “will go down the tubes.” That would be offensive even if it were true, but it is utterly false. The stock market has been on a 10-year run of steady gains that began in 2009, the year Barack Obama was inaugurated. But why would anyone care about that? It’s only an unarguable, stubborn fact. Still, speaking of facts, there are so many measurements and indicators of how the economy is doing, that those not committed to an honest investigation can find evidence for whatever they want to believe. Trump and his most committed followers want to believe that everything was terrible under Barack Obama and great under Trump. That’s baloney. Anyone who believes that believes something false. And a series of charts and graphs published Monday in the Washington Post and explained by Economics Correspondent Heather Long provides the data that tells the tale. The details are complicated. Click through to the link above and you’ll learn much. But the overview is pretty simply this: The U.S. economy had a major meltdown in the last year of the George W. Bush presidency. Again, I’m not smart enough to know how much of this was Bush’s “fault.” But he had been in office for six years when the trouble started. So, if it’s ever reasonable to hold a president accountable for the performance of the economy, the timeline is bad for Bush. GDP growth went negative. Job growth fell sharply and then went negative. Median household income shrank. The Dow Jones Industrial Average dropped by more than 5,000 points! U.S. manufacturing output plunged, as did average home values, as did average hourly wages, as did measures of consumer confidence and most other indicators of economic health. (Backup for that is contained in the Post piece I linked to above.) Barack Obama inherited that mess of falling numbers, which continued during his first year in office, 2009, as he put in place policies designed to turn it around. By 2010, Obama’s second year, pretty much all of the negative numbers had turned positive. By the time Obama was up for reelection in 2012, all of them were headed in the right direction, which is certainly among the reasons voters gave him a second term by a solid (not landslide) margin. Basically, all of those good numbers continued throughout the second Obama term. The U.S. GDP, probably the single best measure of how the economy is doing, grew by 2.9 percent in 2015, which was Obama’s seventh year in office and was the best GDP growth number since before the crash of the late Bush years. GDP growth slowed to 1.6 percent in 2016, which may have been among the indicators that supported Trump’s campaign-year argument that everything was going to hell and only he could fix it. During the first year of Trump, GDP growth grew to 2.4 percent, which is decent but not great and anyway, a reasonable person would acknowledge that — to the degree that economic performance is to the credit or blame of the president — the performance in the first year of a new president is a mixture of the old and new policies. In Trump’s second year, 2018, the GDP grew 2.9 percent, equaling Obama’s best year, and so far in 2019, the growth rate has fallen to 2.1 percent, a mediocre number and a decline for which Trump presumably accepts no responsibility and blames either Nancy Pelosi, Ilhan Omar or, if he can swing it, Barack Obama. I suppose it’s natural for a president to want to take credit for everything good that happens on his (or someday her) watch, but not the blame for anything bad. Trump is more blatant about this than most. If we judge by his bad but remarkably steady approval ratings (today, according to the average maintained by 538.com, it’s 41.9 approval/ 53.7 disapproval) the pretty-good economy is not winning him new supporters, nor is his constant exaggeration of his accomplishments costing him many old ones). I already offered it above, but the full Washington Post workup of these numbers, and commentary/explanation by economics correspondent Heather Long, are here. On a related matter, if you care about what used to be called fiscal conservatism, which is the belief that federal debt and deficit matter, here’s a New York Times analysis, based on Congressional Budget Office data, suggesting that the annual budget deficit (that’s the amount the government borrows every year reflecting that amount by which federal spending exceeds revenues) which fell steadily during the Obama years, from a peak of$1.4 trillion at the beginning of the Obama administration, to $585 billion in 2016 (Obama’s last year in office), will be back up to$960 billion this fiscal year, and back over \$1 trillion in 2020. (Here’s the New York Times piece detailing those numbers.) Trump is currently floating various tax cuts for the rich and the poor that will presumably worsen those projections, if passed. As the Times piece reported: