Comments (4)
Just guessing, but the problem is probably with deepcopy
. It could also be with your method of reading lines. Try rewriting the loop like this:
class Url(Object):
pass
arrayList = []
with open("Input.txt", "r") as fh:
for idx, line in enumerate(fh.readlines()):
arrayList.append(Url(idx=idx, url=line.strip()))
batcher = ParseBatcher()
batcher.batch_save(arrayList)
from parsepy.
Works perfectly. Thanks!!!
But I don't understand why mine isn't... :)
from parsepy.
I take it you're new to Python, and coming from Swift it can look similar in syntax, but there are some crucial differences. I encourage you to read up on the fundamentals of Python and the idiosyncrasies of the language (e.g. Python is primarily pass by reference while Swift is pass by value unless explicitly instructed otherwise).
Your mistake here is abusing deepcopy
. Try to avoid it as much as you can, because it's behavior on custom objects can be unpredictable. In the case of ParsePy, the code uses metaclass features which almost certainly cause problems with deepcopy
. deepcopy
is a serializing function for translating the "value" of the object according to a predefined set of rules, into another object. It's not much different than serializing to JSON. That means that for complex objects with strange behaviors, like those with inheriting from a metaclass, you need to write a custom function to override its default behavior. ParsePy does not have a deepcopy
function implemented on its objects, so this is causing problems.
What was happening:
-
Every iteration of the loop, you overwrote the region of memory where
anyObject
was stored. -
When you called
arrayList.append(deepcopy(anyObject))
, something aboutdeepcopy
failed to copy the object to a new region of memory (probably becauseparsepy
has no__deepcopy__
method defined) -
The next iteration overwrote the memory region of the last iteration
-
The last iteration was the only one to save because there was not an iteration after it to overwrite the value it appended to array.
Some other things:
-
Best practice is to use the
with open('filename.txt') as fh:
when opening files. -
I avoided
deepcopy
by creating the object at time of assignment to function argument. You can create parse objects with keyword arguments rather than creating the object, then changing its values, then deep copying it. By doing this at the same time as assigning the object as the argument toappend()
, I avoid the need to do deepcopy.
from parsepy.
I highly suggest this guide: http://docs.python-guide.org/en/latest/
from parsepy.
Related Issues (20)
- Incorrect URLs for AWS hosted files HOT 2
- Fix for file uploads HOT 4
- parse-py not pointing to the self-hosted server HOT 2
- Ability to access config options. HOT 2
- datetime type in User class HOT 1
- Regex matching for string types does not appear to function HOT 1
- How To Retrieve Objects based on Other Unique Columns
- Cannot use Master Key with a logged in user
- Can't get work any methods HOT 7
- Query constraints
- Batch save isn't working properly HOT 2
- Query Nested attributes HOT 1
- Query for string in array
- SSL: CERTIFICATE_VERIFY_FAILED
- get ACL in an object HOT 1
- Trouble Registering With Bitnami Parse-Server AWS Image HOT 1
- Distinct Queries
- urllib.error.URLError: <urlopen error unknown url type: b'http>, HOT 1
- Proposing a PR to fix a few small typos
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from parsepy.