Traceback (most recent call last): File "<pyshell#1>", line 1, in <module> slowprint(['-'*50, 'This defines BOLD text. This has a specific use', ', such as (<p>Hello <b>World</b>!</p>)', '-'*50]) NameError: name 'slowprint' is not defined
@Kevin thankfully there are always more typists! Anyway, on to our real problem of code quality. Perhaps code review consultants can help? My friend owns a code quality consultancy that could definitely fix this in five expensive years!
----------------------------------------------- The <div> tag is used to create a 'box' that co ntains everything that you put between these ta gs: <div> </div>. This can be used for creating interactive menus, navigations bars, and more! -----------------------------------------------
I need someone to review and improve this code.
import time
import os, signal
User_Name = (input("What is your name?: ")) # If blank twice, sets to John
if User_Name == '':
print("Please enter a name")
time.sleep(1)
User_Name = (input("What is your name?:...
You might be able to refactor a little, by making those sleeps a function that you call, but I don't know if that's worthwhile. Why do you have time.sleep(0.1) several times in a row, rather than time.sleep(0.5)?
If it's invisible ink, then lemon juice will not get it out. Lesson: only use lemon juice on parts that have visible stains, and not parts that may be invisibly stained with things that will become visible when you put a little lemon juice on them.
Should use lemon juice XOR stain is visible = False
hi.....I have a scraper made....I need someone from US to check it for errors(scrape contents are google ads.....not showing in my country) .....pleaseeeee
So I'm undergoing a files directory restructure, and basically if I hit a subdirectory named "NO_DIV" I need to move the contents into the parent folder. Should I be using recursion here alongside my next(os.walk(path))?
the contents could be directories with files etc, or just files
99.9% of the time you want to call it like for dirpath, dirnames, filenames in os.walk(path): and no recursion is necessary whatsoever for it to iterate over every directory contained in path
for dirpath, dirnames, filenames in os.walk(path):
for dirname in dirnames:
if dirname == "NO_DIV":
place_where_files_are = os.path.join(dirpath, dirname)
place_where_files_will_go = dirpath
move_files_somehow(place_where_files_are, place_where_files_will_go)
Hello, I have a general question related of implemented some method from class or some function. For a function for which is requered to return some value, must have return statement on the final in this body? Can this display the result? This implementations can be consider equivalent?
All functions return a value regardless of whether it has a return statement or not. Functions that execute without explicitly returning, will return None automatically.
I can put also others examples, and also I can explain some consequence for portability in design for these. But I prefer to discuss with other...to see if can be other opinions
Are there good reasons why it's a better practice to have only one return statement in a function?
Or is it okay to return from a function as soon as it is logically correct to do so, meaning there may be many return statements in the function?
Well, yeah. Most functions in the wild have some task to do, and unless the task is only about printing, a return value is more often than not used by the caller
This is a huge generalization, but: once you get beyond the "learn Python in 30 days" stage, the vast majority of your functions will have no print statements in them, and very many of them will have return statements.
@Erich That's a bit too unclear to be wrong :P If you're saying it destroys all references that were held by that function, then you're right. If you're saying it destroys any objects, then you're wrong
functions have no self as such, but they can still refer to themselves without using their own name with this simple trick:
def foo():
import inspect
frame = inspect.currentframe()
for obj in frame.f_back.f_locals.values():
if getattr(obj, '__code__', None) is frame.f_code:
self = obj
break
del frame
print(self)
foo()
Google says that you can embed metadata into pdfs. Now I need to figure out how to do it programmatically. Orrr I could see if there are any easy questions on SO I can farm
Does anyone know of a tool that can search every column of every row of every table of a database for a given value? Extra points if it will match a regex.
Non-jokingly: you could reflect the tables with SQLAlchemy then build a query for each table over all columns in each model. It would be insanely slow, but it would get you what you want.
Actually, the simple grep would give you the tablename and column name.
@davidism That's probably for the best. Although autotweeting "I just opened a PDF about the vaccine clinic coming, let's see how long it takes me to response to the Nurse...#don'tdoitthedaybefore" ...would be more fun than what usually happens.
@Funkyguy I assumed that the @property annotation means it uses the ____getattr____ method to figure out what to do rather than actually run the code in the prop method
@Rawing __getattr__ is used when AttributeError is caught. how do you propose Python to distinguish between an AttributeError from a bug inside your property and an AttributeError from an attribute not being there?
I consider it a feature that properties can choose to "not exist" by raising an AttributeError
like, there has to be a mechanism in place that calls the property's __get__ function. All you have to do is to not catch AttributeErrors raised during execution of that mechanism
and it's not like "changed" equals "removed" anyway - they could keep that behavior, but with a different exception and/or only if it's raised directly in the getter
The AttributeError is caught in the code that calls __getattribute__, and that code would have a very messy time trying to figure out where in __getattribute__ the AttributeError occurred and whether the AttributeError was deliberate.
Hmm, I see. That'd be messy to change I guess. But would it be horrible if you had to throw a PretendIDontExistException instead?
Sure, that disappearing colour property is handy, but it might just as well be a bug in your code. If you do if not hasattr(self, color): raise PretendIDontExistException, it'd be clear that it's intentional
I think that's a case of If the implementation is hard to explain, it's a bad idea.
To protect yourself from misbehaviour due to creating some obscure bugs due to this thing, the way is having lots of tests, not overcomplicating the language implementation.
Hi, I'm trying to make my own custom list (dynamic array) using class on python, I got a "AttributeError: 'py_object_Array_40' object has no attribute 'append" when trying to copy the array element by element with a for loop when resizing it, or a memory error when trying to copy it by slicing [:]. Any ideas why?