Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
My questions are about code with this format:
name1.name2()
Question1: I saw this format in python a lot. I want to make sure is it ture that every time I see this format name1 is a module and name2() is a function of this module?
Question2: Is it possible to have name1.name2 (without () in front of name2)? and in this format is name2 a module or function?(My Thought on question2: name2 cant be function because it need "()" to be a function But I am not sure if it is a module or even we have this format.)
Answer 1: Actually you cant be sure at all since it's not necessary for the name1 to be a module. It can be almost anything. And anyhing in Python is an Object :)
The name2, as a result, is probably a method of that Object. So the name1 can be an instance of a class, the class itself, a string, an integer, a module or a package, whatever ...
Answer 2: Yes, it is possible to have that format. The name2 in this case may again be a lot of things, it can be anything that is defined in the name1 object. It can be a property, a function in the module, a module in a package, a method of the Object or anything else.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
Write a program named program52.py that uses main and a void function named numbers that takes no arguments and does not return anything. The numbers function generates 5 random integers, each greater than 10 and less than 30 (duplicates are okay), and prints them all on one line separated by spaces. A loop is required for this, and the loop should also total up the integers so the sum can be displayed when the loop ends. The main function should call the numbers function.
This is the requirements for them, I'm very new and I've had a great deal of trouble using void functions so as you might imagine this has been difficult. I was wondering if anyone had insight on how to do this, I would not like the solution I want to understand how to do it properly.
In python, you don't need to define something to return for your function. It is by default void unless you add a return statement.
Refer to these for how to make functions:
https://www.w3schools.com/python/python_functions.asp, https://realpython.com/python-main-function/
Additionnal sources to help in your work:
https://www.w3schools.com/python/python_for_loops.asp,
https://www.techbeamers.com/python-random-number-tutorial/
You can quickly find answers to this type of question by looking it up on many websites like: W3Schools, GeeksForGeeks, RealPython and many others.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have been trying to sort this error and can't understand why it is happening. tried changing name of the sub and check many times to make sure the spelling is exactly the same but the error keeps ocurring and i can't understand why. Can someone help?
You should not use the same name the module and the procedure. This will cause a conflict.
So if you Call SortDataSource it will find the module name first and of course it cannot call a module (only a procedure or function within a module).
So if you use the same names you need to Call SortDataSource.SortDataSource to make it call the procedure SortDataSource inside the module SortDataSource:
Syntax is like
Call ModuleName.MethodName(Argument1, Argment2)
or without Call which is not needed.
ModuleName.MethodName Argument1, Argment2
But I highly recommend not to use the same name for a module and a procedure. As you can see it can cause errors that can easily be avoided by choosing different names.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am studying the example in section 3 on this page:
https://wiki.haskell.org/State_Monad
Basically, I would like to play with this example but I do not know how to make the code do anything. I take it that this is a "module", and that some modules are "programs" in Haskell, but I don't understand why this module has a function called "main" (I thought it would also have to be called "Main" to be a program, but I tried changing it and it failed to compile). If it is not a program, then what I am supposed to do with a module sitting all by itself? Am I supposed to import it into ghci and then type > main? If so, I tried but I can't make it happen.
The code in the sections titled "complete and concrete example" are complete and concrete examples. You can put the code in these into files with the same name as the module name (i.e. the StateGame module should go into a file called StateGame.hs).
You can then compile that with ghc ghc StateGame.hs -main-is StateGame. Alternatively you can rename that module to Main, then you don't need the -main-is part.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
the parsing of user name has a ' inside of the user name
and i think that is causing the code to break
when i set it with this
tempUsername=Request.Form("UserName")
if (Request.Form("Action") = "Login") then
tempUsername=Request.Form("UserName")
tempPassword=Request.Form("UserPassword")
is that assumption right?
if so what is a solution to this?
Jumping onto the comment by James, as well as answering this question:
Input sanitization is an issue in every language. Even if there weren't ' characters in usernames, this code is danger++
At the very least, run all the data you get from Request.form through a function that escapes/sanitizes dangerous characters in the context of what the data is getting passed on to (such as data stores or dir-resolving code).
As for the code using <%, that's a sign this is an ASP script, and the syntax looks like it's VB. The (Request.Form("Action") = "Login") in particular is a dead give-away, because no sane programming language since the 80s uses "=" as an equality testing operator =)
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I am working on a function that returns an object from a container (e.g an Array) by value (e.g by name). If the object doesn't already exist, then a default copy of the object (default constructor) is created and returned.
That way, this function ALWAYS returns an object, regardless if the object existed prior to calling the function.
Now my question is this: how to name this function? GetOrCreateThenGet sounds stupid. Any ideas?
Edit : I feel something like this would be closer to the function's essence: GetForSure...
The best suitable name for the function would be "Provide" like if you provide goods you can ship it from a warehouse or make/buy a new one and then deliver.
Why do you need anything other than getXXX(). Any method that has and/or means that it is doing to much and is mixing concerns and seriously breaking the Single Responsibility Principle.
Should the caller actually care if the object is being created on demand if all they need from the contract is to get the object?
getOrCreate implies you will get the object or it will be created but not returned.
Again why would I care about the create part?
If I really am supposed to care it would be getOrCreateAndGet to be semantically correct, but highly unorthodox and prone to discussions with peers about methods doing to many things and mixing concerns and breaking the Single Responsiblity Principle? Just because other people name things whacky and non-sensical isn't a good excuse to do it wrong also.
GetGuaranteed seems to cover all the caller needs to know...