Skip to content
Advertisement

Tag: python-3.x

Check the presence of files within directory

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

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 .

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

Advertisement