Is there a blockchain in python

❶ What is python blockchain

is a computer language, blockchain is a decentralized decentralized database protocol, most of the Blockchains are all developed in C++ (for performance reasons). There is no direct relationship between python and blockchain, and few people use python to develop blockchain.

❷ What modules are there in python?

os module
os.getcwd() # Get the current working directory, that is, the current working directory of the python script Directory path
os.chdir(“dirname”) # Change the working directory of the current script; equivalent to cd under the shell cd
os.curdir # Return to the current directory: (‘.’)
os.pardir # Get the string name of the parent directory of the current directory: (‘..’)
os.makedirs(‘dirname1/dirname2’) # Can generate multiple recursive directories
os.removedirs(‘dirname1’) # If the directory is empty, delete it, and recurse to the previous directory, if it is also empty, delete it, and so on
os.mkdir(‘dirname’) # Generate a single-level directory; equivalent to the shell mkdir dirname
os.rmdir(‘dirname’) # # Delete a single-level empty directory, if the directory is not empty, it cannot be deleted, and an error is reported; equivalent to rmdir dirname
os.listdir(‘dirname’ in the shell ) # List all files and subdirectories in the specified directory, including hidden files, and print them as a list
os.remove() # Delete a file
os.rename(“oldname”,”newname” ) # Rename file/directory
os.stat(‘path/filename’) # Get file/directory information
os.sep # Output OS-specific path separator, “\\ under win “,”/”
os.linesep under Linux # Output the line terminator used by the current platform, “\t\n” under win, “\n” under Linux
os.pathsep # The output string used to split the file path is; under win, it is: # The output string indicates the currently used platform. win->’nt’; Linux->’posix’
os.system(“bash command”) # Run the shell command and display it directly
os.environ # Get system environment variables
os .path.abspath(path) # Returns the normalized absolute path of path
os.path.split(path) # Splits the path into a two-tuple of directory and filename and returns
os.path.dirname(path ) # Returns the directory of path. In fact, it is the first element of os.path.split(path)
os.path.basename(path) #
Returns the last file name of path. If the path ends with / or \, then it will return a null value. That is, the second element of os.path.split(path)
os.path.exists(path) # If path exists, return True; if path does not exist, return False
os.path.isabs (path) # Return True if path is an absolute path
os.path.isfile(path) # Return True if path is an existing file. Otherwise return False
os.path.isdir(path) # Return True if path is an existing directory. Otherwise return False
os.path.join(path1[, path2[, …]]) # Return after combining multiple paths, parameters before the first absolute path will be ignored
os .path.getatime(path) # Returns the last access time of the file or directory pointed to by path
os.path.getmtime(path) # Returns the last modification time of the file or directory pointed to by path
os .path.getsize(path) # Return the size of path
sys module
sys.argv # Command line parameter list, the first element is the path of the program itself
sys.exit(n) # Exit the program, exit(0)
sys.version # Get the version information of the Python interpreter
sys.maxint # Maximum Int value
sys.path # Return the search path of the module , use the value of the PYTHONPATH environment variable during initialization
sys.platform # returns the name of the operating system platform
datetime module returns a datetime object representing the current date and time[tz]) returns the datetime object of the specified time zone date and time, if the tz parameter is not specified, the result is the same as above
datetime.utcnow() returns the datetime object of the current utc date and time
datetime. fromtimestamp(timestamp[, tz]) creates a datetime object based on the specified timestamp
datetime.utcfromtimestamp(timestamp) creates a datetime object based on the specified timestamp
datetime.strptime(date_str, format) converts the time Convert the string to a datetime object

❸ Can python be a blockchain?


Blockchain implementation A brief description of the principle

Blockchain technology is a digital accounting technology, the core of which is to record the blocks in which transaction data is stored in an encrypted manner and in the order of time. The blockchain itself is a public database. The system stores the newly born business data in a container called a block, and adds the block to the existing Article ��. It’s a bit like eating a snake. The more blocks it eats, the longer the snake’s body will be; in the application scenario of Bitcoin, these data are a set of transfer transaction records. In the application scenario of shared bicycles, these data can be the transaction records of borrowing and returning the car.

Simple implementation code of blockchain

In the above code, the data structure stored in the core of the blockchain is a list, which can be accessed through
The new blocks generated by new_block() are continuously added to the end of the blockchain. The Hash value of each block contains all the data information of the block, which needs to be quoted in the process of calculating the Hash value. Hash
value of the previous block, so it is tamper-proof. The greatest value of the blockchain database is this highly tamper-proof trusted computing. This is successfully demonstrated in our simple blockchain implementation. In commercial-level blockchain applications, the process of creating new blocks is called smart contracts, and the blockchain is constantly growing through smart contracts.

The following is the running result of the code, under different time, the running result is different.

Running Results

❹ How to use python to develop blockchain

Initial blockchain
A blockchain is an immutable, ordered chain record composed of records of blocks. It mainly has the following characteristics:
1: Decentralization
Due to the use of distributed accounting and storage, there is no centralized hardware or management organization, and the rights and obligations of any node are equal. The data blocks in the system are jointly maintained by nodes with maintenance functions in the entire system. Thanks to the decentralized features of the blockchain, Bitcoin also has decentralized features.
2: Openness
The system is open, except that the private information of the transaction parties is encrypted, the data of the blockchain is open to everyone, and anyone can query the blockchain through the public interface Data and development related applications, so the entire system information is highly transparent.
3: Autonomy
Blockchain adopts consensus-based specifications and protocols (such as a set of open and transparent algorithms) so that all nodes in the entire system can exchange data freely and securely in a trustless environment , so that trust in “people” is changed to trust in machines, and any human intervention will not work.
4: Information cannot be tampered with
Once the information is verified and added to the blockchain, it will be stored permanently. Unless more than 51% of the nodes in the system can be controlled at the same time, the database on a single node will not be tampered with. The modification is invalid, so the data stability and reliability of the blockchain is extremely high.
5: Anonymity
Because the exchange between nodes follows a fixed algorithm, the data interaction is trustless (the program rules in the blockchain will judge whether the activity is valid by themselves), so the counterparty does not need to It is very helpful for the accumulation of credit to allow the other party to trust themselves by revealing their identities.
Compared with traditional distributed databases, there are two main differences:
1: Traditional distributed databases support additions, deletions, and changes, while blockchain only supports search and insertion, and blocks cannot be deleted or modified. .
2: The traditional distributed database is generally a master-slave structure: the structure of master and slaves, in order to ensure high availability, it is implemented by a standby master, and the blockchain is a decentralized database. There is no master-slave structure.
Blockchain and Bitcoin:
When it comes to blockchain, most people talk about Bitcoin. But blockchain is not equal to Bitcoin. Now it is the era of blockchain 3.0, and Bitcoin is just a product of the era of blockchain 1.0.
The evolution of blockchain is:
▪ Blockchain 1.0 – digital currency
▪ Blockchain 2.0 – digital assets and smart contracts
▪ Blockchain 3.0 ——Classification of blockchains for distributed applications in various industries:
Public Blockchains (PublicBlockChains)
Public blockchains refer to: any individual or group in the world can send The transaction can be effectively confirmed by the blockchain, and anyone can participate in its consensus process. The public blockchain is the earliest blockchain and the most widely used blockchain. The virtual digital currencies of the major bitcoins series are all based on the public blockchain. There is only one blockchain corresponding to this currency in the world. .
Industry blockchain: multiple pre-selected nodes are designated by a group as bookkeepers, and the generation of each block is jointly performed by all pre-selected nodes Decision (pre-selected nodes participate in the consensus process), other access nodes can participate in the transaction, but do not ask the accounting process (essentially still managed accounting, but become distributed accounting, how many pre-selected nodes, how to determine each block The bookkeeper becomes the main risk point of the blockchain), and anyone else can do it through the open API of the blockchain.Define query.
Private Blockchain: Only use the general ledger technology of the blockchain for bookkeeping, which can be a company or an individual, and exclusively enjoy the writing of the blockchain Access permissions, this chain is not much different from other distributed storage solutions. (Dec2015) Conservative giants (traditional finance) all want to experiment with private blockchains, while the applications of public chains such as bitcoin have been industrialized, and the application products of private chains are still being explored.

❺ Is it better to learn blockchain or python

Blockchain is a new application mode of computer technology such as distributed data storage, point-to-point transmission, consensus mechanism, encryption algorithm, etc. . The so-called consensus mechanism is a mathematical algorithm that realizes the establishment of trust between different nodes and the acquisition of rights and interests in the blockchain system.
And python is an object-oriented interpreted computer programming language.
You can learn together without conflict and which one is better. I feel that it is python because it is a language that can do a lot of things.

❻ Can python engage in blockchain?

Of course it can
1 import hashlib as hasher
2 import datetime as date
4 # Define what a Snakecoin block is
5 class Block:
6 def __init__(self, index, timestamp, data, previous_hash):
7 self.index = index
8 self.timestamp = timestamp
9 = data
10 self.previous_hash = previous_hash
11 self.hash = self.hash_block()
13 def hash_block(self):
14 sha = hasher.sha256()
15 sha.update(str(self.index) + str(self.timestamp) + str(self. data) + str(self.previous_hash))
16 return sha.hexdigest()
18 # Generate genesis block
19 def create_genesis_block():
20 # Manually construct a block with
21 # index zero and arbitrary previous hash
22 return Block(0,, “Genesis Block”, “0”)
24 # Generate all later blocks in the blockchain
25 def next_block(last_bl ock):
26 this_index = last_block.index + 1
27 this_timestamp =
28 this_data = “Hey! I’m block ” + str(this_index)
29 this_hash = last_block.hash
30 return Block(this_index, this_timestamp, this_data, this_hash)
32 # Create the blockchain and add the genesis block
33 blockchain = [create_genesis_block()]
34 previous_block = blockchain[0]
36 # How many blocks should we add to the chain
37 # after the genesis block
38 num_of_blocks_to_add = 20
40 # Add blocks to the chain
41 for i in range(0, num_of_blocks_to_add):
42 block_to_add = next_block(previous_block)
43 blockchain.append(block_to_add)
44 previous_block = block_to_add
45 # Tell everyone about it!
46 print “Block #{} has been added to the blockchain!”.format(block_to_add .index)
47 print “Hash: {}\n”.format(block_to_add.hash)

❼ What blockchain is python

Python is a computer language, blockchain is a decentralized database protocol without a center, and most blockchains are developed in C++ (for performance reasons). There is no direct relationship between python and blockchain, and few people use python to develop blockchain.

❽ The difference between ‘ and “” in python

If you want to represent a string, then there is no difference.
‘Hello’ and “Hello” are the same for Python.
But when using “”, you can use ‘, such as “Let’s go”


Related Ad

Comments (No)

Leave a Reply