Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python vector
#1
Pyvec is a working incomplete pure python "implementation" of c++ vector wich supports iterators (begin() end()) and more source code github I'm waiting your comments, feel free to open an issue, feel free to create a pull request

from vector import *

v1 = Vector()

# Add 3 elements to vector
v1.push_back("a")
v1.push_back("b")
v1.push_back("c")

print(v1)
print("")

# ['a', 'b', 'c']

assert(v1.empty() == False)

# Remove last element from vector
v1.pop_back()

print(v1) 
print("")
#['a', 'b']

# Add element at specifiec possition
pos = 0
element = "e"
v1.insert(pos, element)

print(v1)
print("")

assert(len(v1) == 3)


# Print all elements using begin() & end()

v = v1.begin()

while v != v1.end():
    print(v[0])
    v +=1



#e
#a
#b


# clear vector 
v1.clear()

print("")
print(v1) 
# []

assert(v1.empty() == True)
Reply
#2
If a i look at your print statements you are still using Python 2.x which is dead.
Python 2.7 clock

Starting a module with python 2.x code is imho not a clever idea.
Reply
#3
(Jul-28-2019, 06:38 AM)ThomasL Wrote: If a i look at your print statements you are still using Python 2.x which is dead.
Python 2.7 clock

Starting a module with python 2.x code is imho not a clever idea.
Hello Thomas you are absolutely right. Thank you
Reply
#4
cvsae Wrote:I'm waiting your comments
What's the point of simulating C++ vector classes API in python? Do you have a particular use case in mind?
Reply
#5
I notice that your repo has a tests directory, but in general testing should be automated.The problem with just having scripts that print stuff is that they require a human to look at the results, which is error prone (say someone misreads the output) and as an application or library grows, time consuming. Therefore, as developers, we prefer to write test code that interacts with the components in the system and verify that the result is correct. Doing this allows us fast feedback when adding or changing functionality (have we broken anything?) and therefore makes sure we can ship working software. Python comes with a test framework in its standard library, unittest and there are also third party libraries (nose2 and pytest, for example).
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020