I am using the Community Edition of PyCharm.
When I put a break point in my python file and try to debug, always file cp1252.py opens and it goes to this line:
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
Do I need to do any specific setting for debugger in PyCharm?
Thanks for the help.
It turned out that I needed to force the source file to be opened as UTF-8 by adding this at the first line of my code:
# -*- coding: UTF-8 -*-
Related
I'm really confused on this one, and maybe it's a bug in Ruby 2.6.2. I have files that were written as UTF-8 with BOM, so I'm using the following:
filelist = Dir.entries(#input_dirname).join(' ')
filelist = filelist.split(' ').grep(/xml/)
filelist.each do |indfile|
filecontents_tmp = File.read("#{#input_dirname}/#{indfile}", :encoding =>'bom|utf-8')
puts filecontents_tmp
end
If I put a debug breakpoint at the puts line, my file is read in properly. If I just run the simple script, I get the following error:
in `read': ASCII incompatible encoding needs binmode (ArgumentError)
I'm confused as to why this would work in debug, but not when run normally. Ideas?
Have you tried printing the default encoding when you run the file as opposed to when you debug the file? There are 3 ways to set / change the encoding in Ruby (that I'm aware of), so I wonder if it's different between running the file and debugging. You should be able to tell by printing the default encoding: puts Encoding.default_external.
As for actually fixing the issue, I ran into a similar problem and found this answer which said to add bin mode as an option to the File.open call and it worked for me.
I've noticed some Ruby files have a section at the very top like the following:
# -*- mode: ruby -*-
An example is a Vagrantfile generated by Vagrant.
What does that section actually do?
It's a file mode specification for emacs
When you visit a file, Emacs chooses a major mode automatically. Normally, it makes the choice based on the file name—for example, files whose names end in ‘.c’ are normally edited in C mode—but sometimes it chooses the major mode based on special text in the file. This special text can also be used to enable buffer-local minor modes.
It basically tells Emacs to use ruby mode
On top of my Vagrantfile I have:
# -*- mode: ruby -*-
# vi: set ft=ruby :
But every time when I open the file, I have to select manually in SublimeText 3 that I wanna set the syntax to Ruby, so it'll be readable.
How can you set a filename to be opened as a ruby-file in this example. Because the file has no extension.
Your use case is exactly what ApplySyntax is written to address. In fact, I believe Vagrantfile is one of the default "samples", so you might not have to do anything. Also, comments that are handled in some special way on some editors does not apply to all editors (in this case, ST).
File.exist? in not working with directory name having special characters. for something like given below
path = "/home/cis/Desktop/'El%20POP%20que%20llevas%20dentro%20Vol.%202'/*.mp3"
it works fine but if it has letters like ñ its returns false.
Plz help with this.
Try the following:
Make sure you're running 1.9.2 or greater and put # encoding: UTF-8 at the top of your file (which must be in UTF-8 and your editor must support it).
If you're running MRI(i.e. not JRuby or other implementation) you can add environment variable RUBYOPT=-Ku instead of # encoding: UTF-8 to the top of each file.
I've actually figured out what causes this error, but Googling for it was unsuccessful so I thought I'd write it down here to help out other people. This error pops up when you've got an # -*- coding: undecided -*- comment at the top of one of your files. Emacs added this automatically for me, but re-saving the file caused it to be changed to the correct # -*- coding: utf-8 -*-.
This error pops up when you've got an # -*- coding: undecided -*- comment at the top of one of your files. Emacs added this automatically for me, but re-saving the file caused it to be changed to the correct # -*- coding: utf-8 -*-.