Comments (8)
also System.out.print
is a syntax error without from __future__ import print_function
, but that isn’t important ;)
if we’d really need it, we could use autoclass('java.lang.System').out.__getattribute__("print")("woo")
from pyjnius.
Confirmed, thanks for reporting, looking into how to add this to our method signature lookup :)
from pyjnius.
nice. please remember to create tags as soon as bigger features like that (or the upcoming import hook) come in, they help with knowing when to package a new version.
from pyjnius.
As an aid for adding this feature (and also as a work around) you can do the following:
# Empty vararg
System = autoclass('java.lang.System')
System.out.printf('string' ,[])
# Note: Using python strings does NOT work
String = autoclass('java.lang.String')
System.out.printf('my string is %s', [ String('this') ])
The reason for this is that Java internally converts the varargs into a single array parameter.
Also note that in addition to getting printed to stdout/stderr, calling printf
also seems to return a PrintStream
object. I am assuming that some special-case code ensures that this does not happen with print
and println
?
from pyjnius.
Thanks for the list tip, i was there too :)
Our parser currently doesn't know if a list in signature is a varargs list or not, seems we are not the first ones to run into this issue, if we can detect that, it should be easy enought to adjust our calculate_score method.
For the unability to build a list of python strings directly, i was about to open a bug report, at least to discuss those workarounds and if we can find a better solution (same issue with building lists of numbers and probably other things).
edit: found about isVarArgs, that allow at least to know if a method is varargs… :)
from pyjnius.
We should convert between python and Java strings always and implicitly. Trying to use autoclass on java.lang.String should yield a warning that you'll be dealing with python strings no matter what you do.
Reason is that python strings can do anything Java strings can do, and this change would make anything easier.
Btw.: so you already translate toString
to __str__
?
from pyjnius.
Ok! sorry it took so long, but we now have at least some basic support of varargs in the varargs_support
branch, test case for printf as been added, more test cases with more exotic objects welcome :)
from pyjnius.
I'll close this since support has been added, feel free to reopen if support is incomplete.
from pyjnius.
Related Issues (20)
- pyjnius 1.4.2 and Cython 3.0.0 HOT 4
- pyjnius build error on s390x HOT 10
- ClassNotFoundException for android.media.midi.MidiManager.OnDeviceOpenedListener HOT 3
- unexpected error for jdk17 HOT 4
- Crashes on Apple M1 HOT 27
- How to add everything under M2 repository to pyjnius classpath? HOT 2
- DeprecationWarning: pkg_resources is deprecated as an API
- pyjnius build error, still coming HOT 10
- Including a JAR on Android HOT 2
- Support mail address is broken HOT 2
- OverflowError: value too large to convert to jshort HOT 4
- How to create Webview with FileChooser HOT 1
- Moderinze `java` code? HOT 2
- installation documentation could be refreshed HOT 3
- Usage without JDK HOT 6
- AttributeError: 'Class' object has no attribute '_JavaClass__cls_storage' HOT 4
- Running python script on Android but in Docker container HOT 1
- Getting a pointer to JavaVM
- Dependency Dashboard
- No jvm.dll found HOT 3
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 pyjnius.