python distorted ascii art [closed] - python-3.3

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Hello good people of Stack Overflow,
It seems that I am back here with an inquiry.
I have 'borrowed' some ascii art off the internet to use in my program, don't worry, I have given full credit to the artist at the end of it. Anyway, no matter how I format it, it is distorting where letters and symbols are placed.
For instance, When the code is this:
'''
___________.._______
| .__________))______|
| | / / ||
| |/ / ||
| | / ||.-''.
| |/ |/ _ \
| | || `/,|
| | (\\`_.'
| | .-`--'.
| | /Y . . Y\
| | // | | \\
| | // | . | \\
| | (') | | (`)
| | ||'||
| | || ||
| | || ||
| | || ||
| | / | | \
""""""""""|_`-' `-' |"""|
|"|"""""""\ \ '"|"|
| | \ \ | |
: : \ \ : :
. . `' . .
'''
(it's part of a list)
When running, it appears to be this:
___________.._______
| .__________))______|
| | / / ||
| |/ / ||
| | / ||.-''.
| |/ |/ _ | | || `/,|
| | (\`_.'
| | .-`--'.
| | /Y . . Y| | // | | \
| | // | . | \
| | (') | | (`)
| | ||'||
| | || ||
| | || ||
| | || ||
| | / | | """"""""""|_`-' `-' |"""|
|"|"""""""\ \ '"|"|
| | \ \ | |
: : \ \ : :
. . `' . .
My question is, is it something I may have done, or is it a bug...
Thanks in advance!
John.
Let me quickly clear a few things up, what I was asking was why it was being printed wrongly in the program output...
Sorry for any confusion caused.
The reason given in the answer marked, was correct, and I ammended my program to fix the error by changing the end of each line, replacing the backslash with a different character.

The problem is that \ is the escaping character. For instance, you may have seen "\n" used to mean a newline and "\t" to mean a tab character. Here you mostly have "\" which means a single literal '\' character, and "\" followed by an actual newline which omits that newline in the produced string.
The simplest solution is to just replace every "\" in your string with "\":
>>> print "//\\\\"
//\\
However, this would of course make it harder to view and edit the ASCII art.
A nice solution for your case is to use raw strings by using an "r" prefix on the string literal:
>>> print r"""/\
... \/"""
/\
\/

Related

Horizontal vs Vertical array delimiters - International

Following up on an earlier question I had about horizontal vs vertical arrays, I have a question about it's respective delimiters.
Problem definition:
Hereby an example of an incorrect way of comparing two arrays:
{=SUMPRODUCT(--({"Apple","Pear"}={"Apple","Lemon","Pear"}))}
The correct way, in case of an English application countrycode would be:
{=SUMPRODUCT(--({"Apple","Pear"}={"Apple";"Lemon";"Pear"}))}
Within an English version (most likely more than just English) of Excel these delimiters would respectively be a comma , for horizontal arrays and a semicolon ; for vertical ones. Plenty of online information to be found on this.
Working on a machine with a Dutch country code on it's application however, it't a complete other story. It does frustrate that my delimiters would both be different, respectively ; and a \. Being able to rather simply retrieve the semi-colon it's proven to be tricky to find any documentation on these delimiters for international version.
Workaround:
Not knowing these delimiters up-front makes it tricky for anyone on a variety of international versions of the application to work with these type of formulas. A rather easy workaround would be to use TRANSPOSE():
{=SUMPRODUCT(--({"Apple";"Pear"}=TRANSPOSE({"Apple";"Lemon";"Pear"})))}
Going through the build-in evaluation we can then retrieve the backslash as the column seperator. Another way would be to use the Application.International property and it's xlColumnSeparator and xlRowSeparator.
Question
We can both find and even override the xlDecimalSeparator and xlThousandsSeparator through Excel (File > Options > Advanced), or VBA (Application.DecimalSeparator = "-") but where can we find:
A place to actually see which xlRowSeparator and xlColumnSeparator are used within your own application, other than the workarounds I described. Looking for an interface similar to thousands and decimal seperator and/or official MS-documentation.
Furthermore (not specifically looking for this), is there:
A place to override them just like the decimal and thousand seperators
If not through Excel interfaces, can we brute-force this somehow through VBA?
I'm very curious if official documentation is present, and/or if the above can be done.
Not claiming this is the right answer, but with the help from comments from other users, maybe the below can clarify things a bit:
With no sign of any official documentation on this matter, and seemingly random row and column delimiters #Gserg showed a trick to retrieve information for any LCID using these unique id's on MS office support under "Create one-dimensional and two-dimensional constants". While this is MS office support information, the delimiters you see there are FALSE. They might come up as . a , a ; a : a \ or even a |. You get this results by changing the LCID from the URL to a LCID of interest, e.g.: fr-fr.
Although there are about 600 different LCID's they all get redirected to a default LCID. With the help of #FlorentB. we discovered that not only the MS office support documentation is wrong, it seems that these delimiters are not that random after all. Looking at countries using a decimal point, they use the , as a column delimiter (a horizontal array) and a ; as a row delimiter (a vertical array). Countries using a decimal comma however use a \ as a column delimiter and a ; for rows respectively.
Changing the system country settings, checking all default LCID's in Excel, we ended up with the matrix below showing all row and column delimiters per default LCID:
| LCID | Row | Column |
|-------|-----|--------|
| ar-sa | ; | , |
| bg-bg | ; | \ |
| cs-cz | ; | \ |
| da-dk | ; | \ |
| de-de | ; | \ |
| el-gr | ; | \ |
| en-gb | ; | , |
| en-ie | ; | , |
| en-us | ; | , |
| es-es | ; | \ |
| et-ee | ; | \ |
| fi-fi | ; | \ |
| fr-fr | ; | \ |
| he-il | ; | , |
| hr-hr | ; | \ |
| hu-hu | ; | \ |
| id-id | ; | \ |
| it-it | ; | \ |
| ja-jp | ; | , |
| ko-kr | ; | , |
| lt-lt | ; | \ |
| lv-lv | ; | \ |
| nb-no | ; | \ |
| nl-nl | ; | \ |
| pl-pl | ; | \ |
| pt-br | ; | \ |
| pt-pt | ; | \ |
| ro-ro | ; | \ |
| ru-ru | ; | \ |
| sk-sk | ; | \ |
| sl-si | ; | \ |
| sv-se | ; | \ |
| th-th | ; | , |
| tr-tr | ; | \ |
| uk-ua | ; | \ |
| vi-vn | ; | \ |
| zh-cn | ; | , |
| zh-hk | ; | , |
| zh-tw | ; | , |
The apparent conclusion is that all countries use a semicolon as a row (vertical) delimiter. And depending on decimal seperator countries use a backslash or comma as a column (horizontal) delimiter within array formulas.
So even without proper MS-documentation, nor a place within the Excel interface (like thousand en decimal delimiter do have), on this matter it is apparent that knowing your country's decimal seperator will automatically mean you either use a \ or , as a column delimiter.
| Dec_Seperator | Row | Column |
|---------------|-----|--------|
| . | ; | , |
| , | ; | \ |
I would happily recieve more information about the above and/or presence of any correct MS office documentation to add to this.
It is possible to do this through native Excel (without VBA or add-ins) by querying Excel's C API, but I don't know of anywhere this is documented.
Go into Excel's Name Manager and click 'New...'. Enter a name such as GetColumnSeparator.
In the 'RefersTo:' box, enter the following to get the column separator:
=INDEX(GET.WORKSPACE(37), 14)
In an Excel cell, you can now enter this:
=GetColumnSeparator
and the comma (in English - or whatever symbol is in use on your machine) will be shown.
For the row separator you need to change the index number to 15:
=INDEX(GET.WORKSPACE(37), 15)
On an English machine, this will be the semicolon by default.
On machines where Excel's 'display language' is not English (meaning Excel's function names are translated), you will need a translated version of the above formula. Again I don't know of any documentation on this, so my best suggestion would be to install the English language pack, enter the formula in English, save the workbook, then revert to your original Excel language and re-open the workbook; Excel will translate the formula automatically.
Note that you will need to save the workbook as macro-enabled (e.g. .xlsm rather than .xlsx).
Sorry this is nearly three years late but I hope it helps.

Incorrect stats_reset value in pg_stat_bgwriter

I am checking the stats of background process by below command:
select * from pg_stat_bgwriter ;
But after resetting the stats by command:
select pg_stat_reset() ;
I am expecting the column stats_reset return the time at which stats reset, but it shows the very old time. Any idea or guidance on this ?
Example output:
checkpoints_timed | checkpoints_req | checkpoint_write_time |
checkpoint_sync_time | buffers_checkpoint | buffers_clean |
maxwritten_c lean | buffers_backend | buffers_backend_fsync |
buffers_alloc | stats_reset
-------------------+-----------------+-----------------------+----------------------+--------------------+---------------+-------------
-----+-----------------+-----------------------+---------------+-------------------------------
2525 | 9 | 193751796 | 322501 | 3162662 | 30839 | 176 | 451310 |
0 | 4120735 | 2016-09-27 08:32:43.638545-05
Thanks
Got the answer in the documentation : Doc- link
bgwriter is the shared among all the databases so it can be reset by different function by the below command:
pg_stat_reset_shared('bgwriter') ;

Write a command to increase or decrease the number of vertical splits

I usually have my Vim screen split into two vertical windows, each of which may be further horizontally split. Sometimes, I want to add or delete a vertical window. Is there a way to detect how many top-level vertical splits there are and add or remove vsplits as necessary?
For example, suppose my screen looks like this:
+--------+--------+
| | |
| | |
+--------+ |
| | |
| | |
| +--------+
| | |
+--------+--------+
I want :Columns 1 to give me
+--------+
| |
| |
+--------+
| |
| |
| |
| |
+--------+
by closing the two right-most windows.
I want :Columns 2 to do nothing, detecting that two columns are already open.
And I want :Columns 3 to give me
+--------+--------+--------+
| | | |
| | | |
+--------+ | |
| | | |
| | | |
| +--------+ |
| | | |
+--------+--------+--------+
I am fine if the function ignores vertical splits within horizontal splits. For example, if I had
+--------+
| |
| |
+---+----+
| | |
| | |
| | |
| | |
+---+----+
and I ran :Columns 2, I would get
+--------+--------+
| | |
| | |
+---+----+ |
| | | |
| | | |
| | | |
| | | |
+---+----+--------+
There is indeed a way, but it is involved; the first step is to count the currently-open vertical windows, and I don’t know of any built-in function that facilitates this. The working approach I found to it is basically to start at the first window (the top of the first — if not the entirety of the first — vertical split), and to then, using wincmd l, move to the next window to the right for as long as wincmd l moves to a new window, adding each to a count of open vertical windows including the first one. (I think this is what Gary Fixler referred to in the comments on the question.)
I started trying to write the code for posting here, and it grew to become larger than any function I would want to put in my ~/.vimrc, so I ended up turning it into a plugin which takes the above approach and provides the :Columns command; see Columcille (on vim.org at http://www.vim.org/scripts/script.php?script_id=4742.) The plugin also provides a command for similarly managing horizontal split windows: :Rows divides the current column (or the main window, if there are no open vertical splits) into the specified number of “rows.”

Performing file type counting in all directories

I have a bash script that gives me counts of files in all of the directories recursively that were edited in the last 45 days
find . -type f -mtime -45| rev | cut -d . -f1 | rev | sort | uniq -ic | sort -rn
I have a directory called
\parent
and in parent I have:
\parent\a
\parent\b
\parent\c
I would run the above script once on folder a, once on b and once on c.
The current output is:
91 xls
85 xlsx
49 doc
46 db
31 docx
24 jpg
22 pub
10 pdf
4 msg
2 xml
2 txt
1 zip
1 thmx
1 htm
1 /ic
I would like to run the script from \parent on all the folders inside \parent and get an output like this:
+-------+------+--------+
| count | ext | folder |
+-------+------+--------+
| 91 | xls | a |
| 85 | xlsx | a |
| 49 | doc | a |
| 46 | db | a |
| 31 | docx | a |
| 24 | jpg | a |
| 22 | pub | a |
| 10 | pdf | a |
| 4 | msg | a |
| 98 | jpg | b |
| 92 | pub | b |
| 62 | pdf | b |
| 2 | xml | b |
| 2 | txt | b |
| 1 | zip | b |
| 1 | thmx | b |
| 1 | htm | b |
| 1 | /ic | b |
| 66 | txt | c |
| 48 | msg | c |
| 44 | xml | c |
| 30 | zip | c |
| 12 | doc | c |
| 6 | db | c |
| 6 | docx | c |
| 3 | jpg | c |
+-------+------+--------+
How can I accomplish this with bash?
Put it into a script, make it executable: chmod +x script.sh and run it with: ./script.sh
#!/bin/sh
find . -type f -mtime -45 2>/dev/null \
| sed 's|^\./\([^/]*\)/|\1/|; s|/.*/|/|; s|/.*.\.| |p; d' \
| sort | uniq -ic \
| sort -b -k2,2 -k1,1rn \
| awk '
BEGIN{
sep = "+-------+------+--------+"
print sep "\n| count | ext | folder |\n" sep
}
{ printf("| %5d | %-4s | %-6s |\n", $1, $3, $2) }
END{ print sep }'
sed 's|^\./\([^/]*\)/|\1/|; s|/.*/|/|; s|/.*.\.| |p; d'
s|^\./\([^/]*\)/.*/|\1 | substitutes ./a/file.xls with a/file.xls.
s|/.*/|/| substitutes b/some/dir/file.mp3 with b/file.mp3.
s|/.*.\.| |p substitutes a file.xls with a xls, if s///p is successful then it also prints to standard out, (to avoid files without extension).
d deletes the line (to avoid printing matching (again) or non-matching lines).
sort | uniq -ic counts each group of extension and directory name.
sort -b -k2,2 -k1,1rn sorts first by directory (field 2), small -> large, and then by count (field 1) in reverse order (large -> small) and numerically. -b makes sort(1) ignore blanks (spaces/tabs).
the last awk part pretty prints the output, maybe you want to put this into a separate script.
If you want to see how each pipe filters the results just try to remove each and you will see the output.
Here you can find good tutorials about sh/awk/sed, etc.
http://www.grymoire.com/Unix/

Example of a scenario written in Gherkin Pirate

From what I can see, Gherkin supports many different languages including Pirate
Could someone list an example of the keywords in pirate and what a scenario may sound like or know of a site that has some example listed?
To get a full list of keywords, simply run cucumber --i18n en-pirate
Currently this returns:
| feature | "Ahoy matey!" |
| background | "Yo-ho-ho" |
| scenario | "Heave to" |
| scenario_outline | "Shiver me timbers" |
| examples | "Dead men tell no tales" |
| given | "* ", "Gangway! " |
| when | "* ", "Blimey! " |
| then | "* ", "Let go and haul " |
| and | "* ", "Aye " |
| but | "* ", "Avast! " |
| given (code) | "Gangway" |
| when (code) | "Blimey" |
| then (code) | "Letgoandhaul" |
| and (code) | "Aye" |
| but (code) | "Avast" |
Also try cucumber --i18n help to see all other possible languages (including Scouse and Australian...)

Resources