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
Don't ask why, but I want to create a Python program that generates a random Python program that is valid for execution. I found a similar thread Searching for a random python program generator , but it's old and all the links except the demonstration http://www.4geeks.de/cgi-bin/webgen.py are dead. And maybe something has changed in these years and it's easier to do such thing?
One of idea is to use quantum collapse algorithm/technique. This would require to make a kind of database, where I describe what symbols can came after previous one. For example after a can come (,, any letter, etc, but never, for example, ). Still I think this will create very gibberish source and I could easily set wrong conditions.
There are two main ways to achieve this:
Use third parties to generate runnable junk code, for instance using yarpgen to generate a valid C program, and then using things to translate that to python like https://github.com/DAN-329/C_to_Python_translator
Write a python code that writes randomly generated functions with random parameters calling eachother, if you just need a bunch of functions calling eachother doing random math operations that should not be that hard to implement.
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 4 months ago.
Improve this question
How to make a discord bot so when I input the following it calculates it:
INPUT:
2.2x100 2.8x100-10%
OUTPUT:
output should be the result of the following:
2.8100 - 2.2100 and then minus 10% of that,
(that equation is subject to change)
How would I do this?
This is not an easy task (if you don't want to be unsafe and eval() code).
You need an infix parser that takes into account order of operations (priorities). If there are parenthesis in your operation, it will be even more complex.
You will then need to evaluate the result with a function that executes an abstract syntax tree generated by the parser (AST).
There is probably libraries that make this easier without being unsafe, but make a google search about all the terms I talked about so you can learn more.
EDIT: also take a look at this link. Not beginner stuff.
Infix Calculator Expression Parser
EDIT 2: Just in case you want the easiest solution with eval(), be careful. A skilled attacker can destroy your computer with malicious code. If you just eval() whatever is sent to the bot, they could really destroy / take control of your computer. Be careful.
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 2 years ago.
Improve this question
I want to merge two exe files through python and I've come to the conclusion that the easiest method of doing this would be to make an executable file that has both exe's in its resources and runs the resources of one exe, then the resources of the other (they do not have to execute simultaneously, rather just be packed into one file and take turns executing).
Any ideas?
The simplest way (which isn't simple at all) would be to first write a program in a compile-able language like c or c++. This program would open itself and look for a delimiter of when the next program begins.
Example:
[exe header][code]{delimiter}[program2]
From there you can read that code and write it into a new exe file (if the second program is a exe) or multiple other ways. Then run the second program. Python could be used to pack the second program onto the first one but...
This is almost exclusively used for malicious programs as the "unpacking" program can be made to not be detected by anti-viruses and the malicious program can be encrypted. Due to this, this is as far as I will go and I won't be giving any examples.
If you have any specific questions about code your working on like errors or unexpected results I am sure many people would be up to helping you. Please let me know if you have any questions!
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 2 years ago.
Improve this question
I am looking for a way to generate random data for testing purposes (around 10000 files). For this testing I have a json schema.
Generation JSchema:
RunTest(){
JSchemaGenerator generator = new JSchemaGenerator();
JSchema schemaBuilding = generator.Generate(typeof(TestClass));
}
The code itself is in C# so ideally I would have a C# code for doing this, though a python solution is also accaptable. I have found a number of questions on this topic that got websites or only focusses on a single prefixed sample but I can't find how to do this in C# (or less preferably python), anybody got any good way of doing this?
As for the reason for doing this: it's two fold: 1 this tests the stability of the system by entering a lot of random data looking for edge cases we haven't thought of and 2 it's a load test. (so basically a smoke+load test)
In Oxygen Developer there is a tool that allows you to generate random JSON files from a JSON Schema, but you need to do this manually from an interface. The action can be found in the Tools menu and it opens a dialog box where you can configure various options for generating the JSON instances.
You can find more details in the user manual: https://www.oxygenxml.com/doc/versions/23.0/ug-editor/topics/json-schema-instance-generator-2.html
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 7 years ago.
Improve this question
New programmer here!
I'm creating my first script on my own, and I have a particular function that is quite large, as in 50 lines.
I understand that theoretically a function can be as large as you need it to be, but etiquette-wise, where is a good place to stay under?
I'm using Python 2.something if that makes a difference.
A good rule of thumb (and it's more a guideline of thumb really) is that you should be able to view the entire function on one screen.
That makes it a lot easier to see the control flow without having to scroll all over the place in whatever editor you're using.
If you can't understand fully what a function does at first glance, it's probably a good idea to refactor chunks of code so that the more detailed steps are placed in their own, well-named, separate function and just called from this one.
However, it's not a hard-and-fast rule, you'll adapt your approach depending on your level of expertise and how complex the code actually is.
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 8 years ago.
Improve this question
I have been making a games using pygame and python and I don't need to make more, separate python files to run my game, but when I look at other peoples programs, they have different files that all work in conjunction with each other for their program to work, why not have all or most of the coding in one file?
I use python 3.2.5 and the corresponding pygame
--- Me in the future --- I apologise for asking this question I didn't know exactly what this website was for and how to ask questions ect. I know know that this website inst for opinions.
People do this because it makes the program more readable.
While writing some code you have to understand the difficulty of the people who will maintain your code.
The main advantages of making it in separate files are:
modularity- By using separate files different modules of the program can be separated into different files. This has many advantages. Whenever a problem occur in some part of the code you can look straight into that file.
Readability- Splitting program into different files helps in making it more readable and beautiful.
easy to maintain- Similar to the advantage told in modularity. Whenever some part of the program needs to be updated it can be done easily.
code reuse- If the program is split carefully into different modules, you can use the same code later when a similar problem has to be solved