There are a number of questions about how to force EXECUTE instead of newline in ipython. But I need the opposite. Consider:
In [9]: import sqlalchemy sqlalchemy.__version__
File "<ipython-input-9-84bd5002c701>", line 1
import sqlalchemy sqlalchemy.__version__
^
SyntaxError: invalid syntax
We can see that there should be two lines: ( 1 ) the import and ( 2 ) the __version__ invocation. Whatever I try I can not separate the two pieces.
One of the suggestions was ctl-v ctl-j: that simply did an EXECUTE again.
Another suggestion was Use %edit {tag} Adding line breaks in ipython : That gave an even more interesting behavior:
n [12]: %edit _i9
Editing... done. Executing edited code...
Out[12]: 'import sqlalchemy \nsqlalchemy.__version__ \n'
So notice: the (vi) editor did its job but then ipython simply converted the newlines to \n and did not interpret the newlines instead it concatenated them
So what key combination will get us the newline here?
Pressing Ctrl+q Ctrl-j should do the trick.
Check this answer here.
Related
Running mongoimport, I get the error:
Failed: read error on entry #2: line 3, column 25: bare " in non-quoted-field
This is line 3:
1,0xcrypton,"Hyderabad, India","'Hyderabad', ' India'",17.38405,78.45636
There are plenty of other questions about this error, but they're all related to double quotes or escaped quotes. There's none of that here. In fact, to be on the safe side I deleted all double quotes from the csv. What's going on?
edit: Also tried removing the entire rest of the csv so it's just this line and the header line. Still getting the error.
Well, this happened because I created the csv using pandas to_csv and used the encoding='utf16' option. Apparently doing so breaks quotation marks.
I'm trying to impute genotype data from the public reference panels but my files fail the file sanity check on Sanger Imputation server and it gives the following error:
failed sanity check :
of Non-ACGTN alternate allele at 1:4635556 .. REF_SEQ:'(null)' vs VCF:'-'
I have tried fixing this in the plink with the following command ./plink --bfile chr1 --recode vcf --out chr1_vcf --missing-genotype -
but then it gives error Underscore(s) present in sample IDs.
--recode vcf to chr1_vcf.vcf ... done.
but I still see '_' in the new coded file.
I would appreciate any help, suggestions and comments.
Thanks
Jasdeep
You will have to replace _ with a different character in your PLINK files before running your code.
See below from PLINK manual
When using --recode vcf, sample IDs are formed by merging the FID and IID and placing an underscore between them. When the FID or IID already contains an underscore, this may make it difficult to reconstruct them from the VCF file; you may want to replace underscores with a different character in PLINK files (Unix tr is handy here).
I'm running redshift_connector in Python under the Window environment. I have .sql file that is the collection of DDLs for the database.
when I execute I get the following error
'cannot insert multiple commands into a prepared statement'
You've probably found a solution for this already, but for the sake of closing the loop, here is mine:
I switched from using redshift_connector to using psycopg2, which does allow multiple commands.
If you need to use redshift_connector, however, there is a little workaround. It might mean updating some of your sql code:
Add a function to your python script which splits the sql into multiple commands, delimited by the ';' character, for example.
The only issue with this is where you need the ';' to mean ';'. For this reason, I added an escape argument, which is where you'd need to update your sql. This allows you to replace the ';' in the sql which the function then replaces with a ';' after it has split out the multiple commands.
Here's the function:
def rc_multicommand(rc_cursor,cs,escape=None):
cs_split = cs.split(";")
for split_command in cs_split:
if not len(split_command) == 0:
if not escape == None:
split_command = split_command.replace(escape,';')
rc_cursor.execute(split_command)
I have a perl code where I access multiple txt files and produce output for them.
While I run the code, the output lines on the console are overwritten.
2015-04-21:12-04-54|getFilesInInputDir| ********** name : PEPORT **********
PEPORT4-21:12-04-54|readNFormOutputFile| name :
PEPORT" is : -04-54|readNFormOutputFile| Frequency for name "
Please note, that the second and third line it should have been like
2015-04-21:12-04-54|readNFormOutputFile| name : PEPORT
2015-04-21:12-04-54|readNFormOutputFile| Frequency for name "PEPORT"
Also, after this the code stops processing my files. The code seems fine. May I know what may be the possible cause for this.
Thanks.
Seems like CR/LF versus LF issue. Convert your input from MSWin to Linux by running dos2unix or fromdos, or remove the "\r" characters from within the Perl code.
As choroba says, I guess you are reading a file on Linux that has been generated on Windows. The easiest fix is to replace chomp with s/\s+\z//or s/\p{cntrl}+\z//
Or, if trailing spaces are significant, you can use s/[\r\n]+\z// or, if you are running version 10 or later of Perl 5, s/\R\z//
I really like to use system shell commands in iPython. But I was wondering if it is possible to loop over the returned values from a call to e.g. !ls. This works:
files = !ls ./*_subcell_cooc.txt
for f in files:
print f
But this does not:
for f in ( !ls ./*_subcell_cooc.txt):
print f
Error is:
File "<ipython-input-1-df2bc72907d7>", line 5
for f in ( !ls $ROOT/*_subcell_cooc.txt):
^
SyntaxError: invalid syntax
No it is not possible, the syntax var = !something is special cased in IPython. It is not valid python syntax, and we will not extend for loops and so on to work with it.
You can do assignment as you show in your first example, but using glob,os and other real python module to do that will be more robust, not much harder, and also work outside of IPython...
For the anecdote Guido was really not happy with IPython half-shell syntax when he saw it last time at SciPy2013.
(Also it uppercase I in IPython please.)