i met interesting issue when im comparing two strings. Im reading data from file and everything works well. But then co-worker send me input file, which is just CTRL+C and CTRL+V of working file. And then miracle happend! VBA is so confused, that cant compare two simple strings and i fell of chair.
If you take a look at image you can see that comparison passed if condition where are two same strings, but it should not. Im a bit confused how this can happen.
So met someone something like this? Im realy start thinking about something like machine revolution from Terminator. (files are both saved in notepad++ and there are no strange characters or something like that)
Progress update
So i tried hints from guys in comments below. and ended with something like this
If CStr(Trim(rowArray(4))) <> (CStr("N/A")) Then
Contentent of rowArray(4) is still "N/A" string as on picture above and excel still thinks this strings arent same. I also saved file in pspad, netbeans, and normal notepad and issue is still same.
Use the immediate window to test the contents of the variable:
For i = 1 To Len(rowArray(4)): Print Asc(Mid(rowArray(4), i, 1)): Next
This will print the ASCII value of each character in the string - you can use this to determine what the extra character(s) are causing the issue.
Related
I have a PDF document with the following sample text (screenshot) -
But when I copy and paste it to either word or other text editors all I see is the weird characters :
I am not quite sure why does it giving me weird square boxes instead of pasting the clear human-readable letters (just like the screenshot). Can someone help me how can I get rid of this issue ? Or at least what shall I do to identify the root cause of this strange issue ?
================== Workaround found ==================
I tried converting the document's corrupted unicode to a standard ANSCI unicode formats. But most of the online services couldn't recognize these garbage/weird characters.
This issue could be resolved by some programming, but I don't want to invest time with the programming approach and preferred on the fly approach.
Finally, as suggested by the user 'mkl', converting this document by using the OCR services like "Sedja"/ "Adobe OCR" resolved by issue.
just wondering how to convert a set of code into comments, without having to go through each individual line of code and put a # at the beginning. Was thinking that maybe there was a quick way to highlight the code and then convert it into comment, atm i'm just cutting it off the code and then re-pasting it in later on.
Much appreciated :)
P.S. i m using Pycharm as my IDE
In jupyter notebook, we select lines of code and press ctrl and / key simultaneously to convert a set of code into comments. Also same for vice versa.
You can try it in Pycharm.
You can use the (""") symbol before and after the text you want to comment out. It is not exactly a comment and more of a text constant, but either way it is often used for documentation, so you can use it for multiline comments except for some cases when it causes unexpected errors
To avoid such cases you could simply use multiple single line comments by selecting the desired lines and using ctrl+/ to comment them out
I'm currently using Google Colab in order to take advantage of its free GPU. I was trying to modify a code that I copy and pasted from machinelearningmaster.com. However, whenever I try to add a new code line, for example "print("some words"), I get an indention error.
I have tried adding tabs or spaces before the print call but I still get the error. for example:
space,space,print("some words")
tab, tab ,print("some words")
I have also checked the colab editor settings, currently the indention width setting are set to two spaces.
The first three lines are part of the original code, the print statement is
my addition. I copy and pasted this directly from the colab editor. In Colab all four lines are aligned. As you can see here only the first three lines are aligned. I don't know what's going on.
img_path = images_dir + filename
ann_path = annotations_dir + image_id + '.xml'
count=count+1
print("this is count: ", count)
I expected this to print the value of count, instead I get an error message telling me:
IndentationError: unindent does not match any outer indentation level
Okay, after much searching and frustration, I have an idea of what went wrong, but even better, a solution to fix it.
It appears that the Google Collaborator (Colab) editor does not have a way to set it for tabs "\t" versus space (space-bar entries). From the settings tab on the cell you can set the width of the tab from 2 to 4, but these will be interpreted as 2 to 4 space-bar entries. Usually, this isn't a problem. However, if you're like me and you want to test out code from the web, or be lazy and just copy paste from your editor, problems can arise.
Here's how I fixed it. Before pasting the copied code into Colab, first put it into notepad++. Go to View> Show Symbols >Show All Characters, click on this, you should now be able so see all the characters in the code. Find a tab, it will look like an arrow pointing to the right -->, right click and copy it. Open Search> Find, open the Replace tab. Depending on your version of notepad++ the tab you copied will automatically be entered and the replace will already be set to four spaces. Hit "Replace all". This will automatically replace all tabs with equivalent spaces. Copy the code from notepad++ back to Colab. Now there will be no more conflicts.
I think using a simple find and replace tool will just work fine. I also came across this error recently in Colab and I went through #Rice Man solution. The only difference was I used Libre office writer instead of Notepad++. I also found this tool to be helpful. I am not proficient in using Colab but this solution worked for me.
Another quick fix that worked for me related to this question.
I was trying to run a python script in colab and faced this error though the line seems at an appropriate indentation in that script.
I checked with the !cat filename.py cmd, and found out that the actual indentation appears different than it is in the script (hence the error).
Taking that unindented line (according to the colab) at the start of the line and using space afterward fixed the error.
I used this website to fix the error.
Copy your code to the site, then click beautify button on top left. This will remove indention errors.
If you want to know where the indention error is coming from, use #Prachi answer.
I've got a bit of an annoying issue, I'm trying to write a series of json data to a text document, however, python raises a UnicodeEncodeError whenever it encounters these kinds of characters.
As per the big update with python 3, these characters print to the console just fine, its the issue when we go
with open("filename.txt", "a") as file
file.write("I ♥ ice cream")
file.close()
As I'm still a newbie to python, I haven't the slightest clue how to solve this, any ideas?
Found out how to solve this one!
First off I'd like to thank #JJJ, for hinting me down the right track, however my only criticism is that the presented solution wasn't very straight forward, and for someone with no knowledge of the significance of bytes and strings this may present quite the challenge.
Basically the problem was to do with the default method of encoding that my computer uses (the OS being the standard win 10), being cp1252.
When going into python and having the program run a simple bit of code to test this, it more clearly illustrates the issue and thus we can find a more viable solution.
text = "I ♥ IceCream"
text = text.encode("cp1252")
open('People Jobs.txt','a').write(text)
Running this in IDLE, we get this:
UnicodeEncodeError: 'charmap' codec can't encode character '\u2665' in position 2: character maps to <undefined>
Ah! Now we can see our issue! The codec can't encode the character! Knowing this we can encode the string using utf-8 before writing it to the file like so:
text = "I ♥ IceCream"
text = text.encode("utf-8")
open('People Jobs.txt','a').write(text)
Running this, we finally get:
b'I \xe2\x99\xa5 IceCream'
Which can be written to the file no worries. We can turn this back into the original message using the decode method, however for my purposes, we don't need to do that.
Once again, I'd like to extend my thanks to those who commented on my post, your extensive knowledge of the python language is quite the asset and I greatly appreciate it.
Hopefully my negligence to see these simple programming principles will benefit others when they come to laugh at this post
But hey that's why I have the name!
So until next time,
Mr Incompetent
P.S #Pratik K Thank you for the reminder of how to write this one in a more compact manner, I appreciate it :) (been doing C++ for a while so I've forgotten about python)
I tried it out, seems to work just fine. Just a side note, instead of using with ..., you can just as well write this out as: open(filename, 'a' ).write(string). This will open up the file, write/ append to it, and close it, all within one line.
Just to be clear, the syntax for your solution would be:
with open("filename.txt", 'a') as file:
file.write("I ♥ ice cream")
so i got an issue with text formatting and i have no idea how this problem is called or what i should search after, so i thought i try to explain it here.
It's literally nothing dramatic or should take long, i simply want to write stuff like
''italic'' or '''bold'''
without that it actually gets italic or bold... i literally want
''italic''
to be displayed. I've also tried to use code blocks but even within the blocks it writes italic then.. i'm sure there is a <..> command but i simply can not find it
Does anyone know?
try this:
<nowiki>''italic''</nowiki>