under “mypath” i have one folder and under this folder i have files and i want to check the existance of files under this folder, but in my example below it checks only the directory where is the folder (where there is no files) , So any idea? Answer You need to check the right directory: Like @tdelaney’s answer, does
Tag: python-3.x
How to compare 2 different csv files and output the differences without CSV-diff
I have 2 CSVs which are New.csv and Old.csv shown below: New.csv Old.csv If there is a longName (first column) in in the new.csv that is not in the old.csv, I would like that entire new.csv row to be appended to the changes.csv. The current code below is done with csv-diff which seems be a bit glitchy and hard to
How to generate random number by given string in python?
As hash function gives different values in different python interpreters , Is there a more stable one in python ? Update one: “stable” means that the function should give the same number when the string is same anytime. hash can’t do it . I want a function like : For example , generate_random_number_by_string(“16”) should be the same in anytime .
How do I get VSCode to recognize Python3 as my default
I have python3 install on my Mac and I’m in the terminal, I use python3 by default. However when I’m in VSCode it is not recognizing python3 as my default, it’s still pulling in python2.7. Here is a screenshot of my VScode environement: I have code-runner with python3 selected as well as my interpreter as 3.8 When I run my
NameError: name ‘buffer’ is not defined
Python2 code: What is the python3 equivalent? I tried to replace buffer with memoryview() but than name error becomes a type error: TypeError: memoryview: a bytes-like object is required, not ‘str’. I’m pretty sure that this should be a string and not a byte. Can someone help me? Buffer function for python 3+ IS NOT THE ANSWER! Answer Adapting answers
How to change column value with pandas .apply() method
I stumbled upon an issue while trying to take data from a CSV file, assemble a key and then creating a new CSV file with only the necessary data. Example data: ID1 Data1 Data2 Price1 Color Key ID2 Data3 Price2 12345/6 950/000 Pd950 996 G 4/20017/6 4/20017/6 950/000 1108 12345/6 333/000 Pd333 402 G 4/20017/6 4/20017/6 333/000 501 12345/6 500/000
Check if an item is an instance but not a subclass
How can you check if an object is an instance of a class but not any of its subclasses (without knowing the names of the subclasses)? So if I had the below code: what would go in the #code space that would produce the output?: Because issubclass() and isinstance() always return True. Answer The object.__class__ attribute is a reference to
Python ctypes behaviour with variable types
I’m using a third party python library, that is using ctypes (it uses a dll). I’m not very familiar with ctypes. The lib offers a type definition and a structure definition as given in the minimum example below. I’m trying to assign the member variable myClassInst.MSGTYPE the value of the constant MYConst. Afterwards I want to check the value with
Python grading system using if and for
I have list of name = jimmy, carolin, frank, joseph and their score is = 100 , 90, 70, 65 The grades are : and I put it like this I need to make it like this: Can some one help me please? Thank you in advance! Answer I added everything in one print statement, hope you can understand. Your
Visual Basic Code: Terminal not showing current directory
This is a follow-up to the following question VSCode Python version defaults to 2.7 in the integrated terminal no matter what I do. I would have left it as a comment, but I don’t have enough reputation. I am running VSCode 1.50.1 on macOS High Sierra 10.13.6. I had a problem where the version of Python on integrated terminal defaulted